The program's objective is to manipulate data inside a 2D-array.
int main(void)
{
int array[500][500];
int x0, y0;
if ( input(array, &x0, &y0)==0 )
return 1;
return 0;
}
int input( int array, int *x0, int *y0 ) {
int x = 0;
int y = 0;
int err = 0;
char c;
printf("Enter sizes:\n");
if ( scanf("%d %d", x0, y0)!=2 || *x0<=0 || *y0<=0 || *x0>500 || *y0>500 ) {
printf("Invalid input.\n");
return 0;
}
while ( y < *y0 ) {
x = 0;
while ( x < *x0 ) { //reading entries in x coordinate
c = getchar();
switch(c) {
case 'o' : array[y][x] = 1; break;
case '.' : array[y][x] = 0; break;
case '!' : array[y][x] = 2; break;
default : err = 1; break;
}
x++;
}
if( x!=*x0 )
err=1;
y++; //move to another "line"
}
if (y!=*y0)
err=1;
if (err==1) {
printf("Invalid input.\n");
return 0;
}
return 1;
}
The program will firstly get dimensions of the array and then get one of the three letters: o, ! or . for example:
3 3
ooo
.!o
...
The problem is that my function doesn't accept its arguments: input(array, &x0, &y0) which leads to me being unable to write into that array in the switch. In the former case passing argument 1 of 'input' makes integer from pointer without a cast while in the latter subscripted value is neither array nor pointer nor vector.
My previous program used a 1D array and this way of passing arrays into functions worked.
So how should I pass my array as an argument into functions? Thanks in advance.