You have an array of 20 string pointers.
Each of these points to the same memory (
temp
).
Because that is used for reading the user input within a loop, it contains the last input string.
You can use a two-dimensional array instead:
char stringArray[20][5];
int i;
for (i=0;i<20;i++)
{
scanf("%4s", stringArray[i]);
}
Note that I have increased the input string size (there must be always one more character to store the terminating
NULL
byte) and added that limit also to the
scanf
format string.