函数错误:预期的')'在“char”之前
这是一个程序,可以创建一个充满积分的表,但是我正在尝试分开功能。 我这样做是因为我将来需要使用变量X和Tabuleiro添加更多功能。我在标题中遇到错误,我不明白为什么。你们能帮我吗?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char tabuleiro_init(int dim, char tabuleiro[15][15]);
int main(int x)
{
printf("Put the dimension of the table: ");
scanf("%d", &x);
char tabuleiro[15][15];
tabuleiro_init(x, tabuleiro[15][15]);
}
char tabuleiro_init(dim, char tabuleiro)
{
if (dim >= 7 && dim <= 15 && dim%2 != 0)
{
for (int i = 0; i < dim; i++)
{
for (int j = 0; j < dim; j++)
{
printf(".", tabuleiro[i][j]);
printf(" ");
}
printf("\n");
}
}
}
This is a program to create a table full of points, but i'm trying to separate in functions.
I am doing this because I will need to add more functions in the future using the variables x and tabuleiro. I'm getting the error in the title and I don't understand why. Can you guys help me?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char tabuleiro_init(int dim, char tabuleiro[15][15]);
int main(int x)
{
printf("Put the dimension of the table: ");
scanf("%d", &x);
char tabuleiro[15][15];
tabuleiro_init(x, tabuleiro[15][15]);
}
char tabuleiro_init(dim, char tabuleiro)
{
if (dim >= 7 && dim <= 15 && dim%2 != 0)
{
for (int i = 0; i < dim; i++)
{
for (int j = 0; j < dim; j++)
{
printf(".", tabuleiro[i][j]);
printf(" ");
}
printf("\n");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
声明与
tabuleiro_init
函数的定义之间存在不匹配。第一个参数进行比较
与
,您在定义中缺少
int
。对于第二个参数,您将其声明为
char tabuleiro [] [15]
,或指向char> char
15个元素的指针,但您将其定义为仅仅是char
。There is a mismatch between the declaration and the definition of your
tabuleiro_init
function.Compare
with
For the first parameter, you are missing
int
in the definition.For the second parameter, you declared it to be
char tabuleiro[][15]
, or a pointer to achar
array of 15 elements, but you defined it to be just achar
.对于初学者来说,这个 main 声明
是不正确的。
像这样声明函数
,并在函数内声明变量
x
,就像在这个调用中,
第二个参数是 char 类型数组中不存在的元素,
而是写
在其定义中的函数声明不对应第一个函数声明
且第一个参数没有类型说明符。
此外,函数的返回类型
char
没有任何意义,而且该函数什么也不返回。因此,在这两种情况下至少使用以下函数声明
在 printf 的调用中,
不使用第二个参数。也许您只是意味着
(这没有什么意义),或者
但在最后一种情况下,必须在将数组传递给函数之前对其进行初始化。
For starters this declaration of main
is incorrect.
Declare the function like
and within the function declare the variable
x
likeIn this call
the second argument is a non-existent element of the array of the type char
Instead write
The function declaration in its definition does not correspond to the first function declaration
And the first parameter does not have a type specifier.
Also the return type
char
of the function dies not make a sense and moreover the function returns nothing.So at least use the following function declaration in the both cases
In this call of printf
the second argument is not used. Maybe you just mean
(that does not maje a great sense) or
but in the last case the array must be initialized before passing it to the function.