Hi all,
I have a problem with this code. Can somebody explain to me what this line does p = (char (*)[SZ])in;
I know that "in" is beeing casted but its strange when i see it with pointers. What is exactly happening in memory, what is p pointing at?
And also what is the difference between
char (*p)[SZ]; and char *p[SZ];
thx.
Code:
#include <stdio.h>
#define SZ 3
char print(char c) {
return c >= ' ' && c <= '~' ? c : '#';
}
void fooey(char *in, char *out, int size) {
char (*p)[SZ]; /*p points to array[s] of SZ chars each */
int r, c, i;
p = (char (*)[SZ])in;
for(c = i = 0; c < SZ; c++)
for(r = 0; r < size/SZ; r++, i++) {
out[i] = p[r][c] && p[r][c] != ' ' ? (p[r][c] | ' ') + 1 : p[r][c];
printf("%d=%c,(%d,%d)=%c\n", i, print(out[i]), r, c, print(p[r][c]));
}
}
int main( ) {
char test[9] = "NFCGNX N",
test2[sizeof test];
fooey(test, test2, sizeof test);
printf("%s\n", test2);
return 0;
}