i have this code which tries to enter data into an array of string(char ptr) called token.To do this i have used a while loop to obtain a string as user input and put that string into the token array one by one. But when i try to print the token array outside while loop all the token array elements are equal to the last user entered element in while loop.
Output : the screenshot of output is attached in the post.
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main(int argc, char **argv)
{ int i=0,j=0;
char *token[20];
char buff[20];
while(i<5)
{
printf("\nenter value :");
gets(buff);
token[i]=buff;
i++;
}
for(j=0;j<5;j++)
{
printf("\n%s",token[j]);
}
return 0;
}