I am trying to pass a 2D array to a function that I have defined in my program, but for some reason, I am continuously getting an error about conflicting types for the function call and definition. I am not entirely sure what could be causing the issue since I have not only included the right header, but also used the proper parameter type in the function indicating that it is a 2D array. Below is the code that I am writing.
#include <stdio.h>
#include <stdbool.h>
int main()
{
char array[6][6] = {
{'.', '.', '.', '.', '.', '.'},
{'.', '.', '.','.', '.', '.'},
{'.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.'},
{'.', '.', '.', '.', '.', '.'}
};
bool success = testFunction(array, 0, 1);
return 0;
}
bool testFunction(char array[][6], int i, int j){
return true;
}
And this is the error that I receive after running the program:
main.c:21:6: error: conflicting types for ‘testFunction’
21 | bool testFunction(char array[][6], int i, int j){
It's really confusing me and after looking at previous posts on StackOverflow I cannot seem to find what could be causing this issue. I know this problem could possibly be solved if I converted the array into a pointer, but is it not possible to pass 2D arrays to function? If anyone could help me find a way to solve this, I'd truly appreciate it. Thank you.
CodePudding user response:
You need to define it before the main function or put there the function prototype
bool testFunction(char array[][6], int i, int j);