I'm having some trouble understanding how pointers work with two dimensional arrays. Even the error messages aren't helping me. I have a 2D array that I need a pointer for so I may manipulate it inside of functions (I think that's how you're supposed to do it anyway). Could someone please point out what I'm doing wrong and point me in the right direction?
Here's my code:
#include <stdio.h>
#include <time.h>
void init(char *array);
int main(int argc, char *argv[]) {
char grid[21][80];
char (*grid_ptr)[80];
grid_ptr = grid;
int i, j;
init(*grid_ptr);
for (i=0; i<21; i++) {
for (j=0; j<80; j++) {
printf("%c", grid_ptr[i][j]);
}
printf("\n");
}
return 0;
}
void init(char *array) {
int i,j;
for (i=0; i<21; i++) {
for (j=0; j<80; j++) {
*array[i][j] = ' ';
}
}
for (i=0; i<21; i++) {
*array[i][0] = '|';
*array[i][79] = '|';
}
for (i=0; i<80; i++) {
*array[0][i] = '-';
*array[20][i] = '-';
}
}
The errors are of this nature:
main.c:27:16: error: subscripted value is not an array, pointer, or vector
*array[i][j] = ' ';