array of strings confused me
I wrote this function to get 10 strings from the user, each with a max of 80 characters. it's an array of pointers to strings. when the first for loop executes it seems to be working fine but then when the second executes to check to see if the strings were stored, it just outputs the last string 10 times. what the heck...
Code:
void getstrings(char * star[MAX])
{
int count;
char * buf;
for (count = 0; count < MAX; count++)
{
fgets(buf, LIM, stdin);
*(buf + strlen(buf) - 1) = '\0';
puts(buf);
star[count] = buf;
puts(star[count]);
}
for (count = 0; count < MAX; count++)
{
puts(star[count]);
}
}