I have an array of char
s, and it is initialized using a nested for
loop.
How do I access each element of the array such as a[i][j]
using a char
pointer?
I have tried * (* (p+i)+j)
which gives me a unary error. I have also tried the following:
char a[maxr][maxc];
char *p = 0;
p = &a[0][0];
int i,j;
for (i = 0; i < r-1; i++){
for (j = 0; j < c-2; j++){
while (*p != '\0'){
*p = 'Y';
p++;
}
}
}
If i do:
char a[maxr][maxc];
char *p = 0;
p = &a[0][0];
int i,j;
for (i = 0; i < r-1; i++){
p = p+i;
for (j = 0; j < c-2; j++){
p = p+j;
while (*p != '\0'){
*p = 'Y';
p++;
}
}
}
This seems to traverse the array; however, I am not quite sure if it is the correct way to do it.