Hi every one, I want to write a function that can do some work on a 2D array. I read that functions don't return arrays and the best way would be to set the arguments of the function as pointers to the array I want to work on. The actual program is long and requires a lot of prerequists so I made a much shorter program showing basically the same problem;
I get this error when I compile this program;Code:#include <stdio.h> void testfunction(int *array[][10]); int main (void) { int testarray[10][10], i, j; for(i=0; i<10; i++){ for(j=0; j<10; j++) testarray[i][j]=0; } testfunction(&testarray[][]); for(i=0; i<10; i++){ for(j=0; j<10; j++) printf("%d\n", testarray[i][j]); } return 0; } void testfunction(int *array[][10]){ int a, b; for(a=0; a<10; a++) { for(b=0; b<10; b++) *array[a][b]=a*b; } }
Could any one please guide me in this problem or introduce me to a better method to work on a 2D array inside a function? It would be greatly appreciated, thanks...Code:test.c:10:28: error: expected expression before ‘]’ token



2Likes
LinkBack URL
About LinkBacks



