函数错误:预期的')'在“char”之前

发布于 2025-01-20 08:00:31 字数 779 浏览 4 评论 0原文

这是一个程序,可以创建一个充满积分的表,但是我正在尝试分开功能。 我这样做是因为我将来需要使用变量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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离去的眼神 2025-01-27 08:00:31

声明与tabuleiro_init函数的定义之间存在不匹配。

第一个参数进行比较

char tabuleiro_init(int dim, char tabuleiro[15][15])

char tabuleiro_init(dim, char tabuleiro)

,您在定义中缺少int

对于第二个参数,您将其声明为char tabuleiro [] [15],或指向char> char 15个元素的指针,但您将其定义为仅仅是char

There is a mismatch between the declaration and the definition of your tabuleiro_init function.

Compare

char tabuleiro_init(int dim, char tabuleiro[15][15])

with

char tabuleiro_init(dim, char tabuleiro)

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 a char array of 15 elements, but you defined it to be just a char.

为人所爱 2025-01-27 08:00:31

对于初学者来说,这个 main 声明

int main(int x)

是不正确的。

像这样声明函数

int main( void )

,并在函数内声明变量x,就像

int x;

在这个调用中,

tabuleiro_init(x, tabuleiro[15][15]);

第二个参数是 char 类型数组中不存在的元素,

而是写

tabuleiro_init(x, tabuleiro);

在其定义中的函数声明不对应第一个函数声明

char tabuleiro_init(dim, char tabuleiro)

且第一个参数没有类型说明符。

此外,函数的返回类型 char 没有任何意义,而且该函数什么也不返回。

因此,在这两种情况下至少使用以下函数声明

void tabuleiro_init(int dim, char tabuleiro[15][15])

在 printf 的调用中,

printf(".", tabuleiro[i][j]);

不使用第二个参数。也许您只是意味着

printf("." );

(这没有什么意义),或者

printf(".%c", tabuleiro[i][j]);

但在最后一种情况下,必须在将数组传递给函数之前对其进行初始化。

For starters this declaration of main

int main(int x)

is incorrect.

Declare the function like

int main( void )

and within the function declare the variable x like

int x;

In this call

tabuleiro_init(x, tabuleiro[15][15]);

the second argument is a non-existent element of the array of the type char

Instead write

tabuleiro_init(x, tabuleiro);

The function declaration in its definition does not correspond to the first function declaration

char tabuleiro_init(dim, char tabuleiro)

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

void tabuleiro_init(int dim, char tabuleiro[15][15])

In this call of printf

printf(".", tabuleiro[i][j]);

the second argument is not used. Maybe you just mean

printf("." );

(that does not maje a great sense) or

printf(".%c", tabuleiro[i][j]);

but in the last case the array must be initialized before passing it to the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文