This is my code and it is not working.
It generate these errors when I pass char array like this grid[r][c]
[Error] use of parameter 'r' outside function body
[Error] use of parameter 'c' outside function body
It generate these errors when I pass char array like this grid[][c]
[Error] use of parameter 'c' outside function body
It generate these errors when I pass char array like this grid[][]
[Error] declaration of 'grid' as multidimensional array must have bounds for all dimensions except the first
And it runs perfectly fine when I pass this like this grid[1][2] i.e. just passing with an integer.0
I am stuck here and I don't know what to do or what not??
How to get rid of this problem?? Help Me !!!
Thanks in Advance!
void dfs(int r, int c, int pacman_r, int pacman_c, int food_r, int food_c, char grid[r][c]) {
//logic here
}
int main(void) {
int r, c;
int pacman_r, pacman_c;
int food_r, food_c;
scanf( "%d %d", &pacman_r, &pacman_c);
scanf( "%d %d", &food_r, &food_c);
scanf( "%d %d", &r, &c);
char grid[r][c];
for( int i=0; i<r; i++) {
scanf("%s[^\\n]%*c", grid[i]);
}
dfs( r, c, pacman_r, pacman_c, food_r, food_c, grid);
return 0;
}
char *instead of a 2D array.) alsoscanf("%s[^\\n]%*c", grid[i]);wrong.