What am I doing wrong here? The first one works like a charm the second one crashes.
char *t[3][4] = {
{"one", "two", "three", "Four"},
{"Five", "Six", "Seven", "Eight"},
{"Nine", "Ten", "Eleven", "Twelve"}
};
int i,j;
for (i=0;i<3;i++) {
for (j=0;j<4;j++) {
printf("%s\n",t[i][j]);
}
}
Same array just want to use in function:
foo(t, 3, 4);
char **foo(char **t, int row, int col) {
int i,j;
for (i=0;i<row;i++) {
for (j=0;j<col;j++) {
printf("%s\n",t[i][j]);
}
}
}
Process terminated with status -1073741510 (0 minute(s), 8 second(s));
char **foo(char **t, int row, int col)-->void foo(int row, int col, char *t[row][col]) (callfoo(3, 4, t);)char ***(which would be incorrect as a 2D array ofchar *is not a pointer-to-pointer-to-pointer-to-char) or just thought achar **would refer to an array ofchar *regardless of the number of dimensions (also not right, but a different misunderstanding)...tin the argument list offoodoes not match the type oft, the array. When I compiled your code, I got errors (because I convert warnings to errors with-Werror) like:asp19.c:22:9: error: passing argument 1 of ‘foo’ from incompatible pointer type [-Werror=incompatible-pointer-types]identifying the linefoo(t, 3, 4);and observingasp19.c:3:6: note: expected ‘char **’ but argument is of type ‘char * (*)[4]’referring tovoid foo(char **t, int row, int col);