In my main I have
int mat[ROW][COL];
int *p = &mat[0][0];
minput(p, ROW, COL);
I'm stuck on how to make minput, because I'm supposed to initialize the 2d array with set numbers, but I just don't understand how I'm supposed to assign the numbers,
I get that m[0][0] in pointer is *(*(m+0)+0), but it doesn't let me do something like *(*(m+0)+0)=0;,
because it gives the invalid type argument of unary ‘*’ (have ‘int’) error.
So basically I just want to know how to assign a number to a 2d array using pointers, if we didn't have to use pointers this would be so easy with m[2][2]=5 and whatever but I have no idea how to do this with pointers.
My prof provided a one line example of the minput function and it was just *(m+0) = 8;, which doesn't make sense to me, isn't that what we use for a 1d array? if that's the way to do it then does that mean I'm supposed to do something like
*(m+0) = 8;
*(m+1) = 1;
*(m+2) = 6;
*(m+3) = 3;
*(m+4) = 5;
*(m+5) = 7;
*(m+6) = 4;
*(m+7) = 9;
*(m+8) = 2;
for a 3x3 array? it doesn't seem right to me, It would be great if someone could help me out with this, pointers are very confusing to me.
EDIT: so I see that apparently the correct way to do it is the way I listed above with the
*(*(m+0)+0) = val
but when I do this in my code, I get the this error:
error: invalid type argument of unary ‘*’ (have ‘int’)
*(*(m+0)+2)=6;
^
why is this the case? is the assignment wrong?
f(int arr[ROW][COL])? Anything else is just nonsense. (That is converted toint (*)[COL], but you can use 2D indexing as usual). And makepthe correct type, too!