Home > Software engineering >  Function error: expected ')' before 'char'
Function error: expected ')' before 'char'

Time:04-11

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");
        }
    }
}

CodePudding user response:

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.

CodePudding user response:

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.

  • Related