I hope I'm in the right place for this topic. I'm having a bit of trouble understanding how pointers work in C. I'm making a program to keep track of 3-dimensional arrays of characters, but keep getting segmentation faults so I made a short program to help me understand pointers:
char input[100], *pointer[3];
int i, j;
for(i = 0; i < 3; i++)
{
scanf("%s", input);
pointer[i] = input;
}
for(i = 0; i < 3; i++)
{
j = 0;
while (pointer[i][j] != '*')
printf("%c", pointer[i][j++]);
printf("\n");
}
The program expects 3 lines of input with a * somewhere to end each input line. What I expect to be output, is those three lines up until a * is encountered, but instead, it gives the LAST line three times. What am I missing?