-2

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");
        }
    }
}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • 2
    2nd function, ‘int’ missing in header before ‘dim’. – 500 - Internal Server Error Apr 10 '22 at 23:43
  • Be sure to turn up the warning level on your compiler. There are other issues that you will need to fix for this code to actually run properly. – Retired Ninja Apr 10 '22 at 23:45
  • 1
    Welcome to SO. Whenever you ask because you get an error message, please add the exact error message into the question. The message should contain the location where it was detected. With that message and location, we don't need to check the whole code for something that might causing such a message. Instead we immediately know where to start searching. – Gerhardh Apr 11 '22 at 06:07

2 Answers2

0

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.

aafulei
  • 2,085
  • 12
  • 27
0

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.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335