I have an array of chars, 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.
athis is not possible to answer accurately. An array of arrays vs an array of pointers will have different answers. Update the question to include the declaration ofaplease.ais there ... The markdown was failing but I fixed it.