I am trying to read in two lines using fgets, but only the first line is read and then returns a segmentation fault. I'm not sure what I would need to change for it to read in the second line. Any help would be appreciated!
int main(void)
{
char str[100];
char *word;
//First Line
fgets(str, 100, stdin);
printf("%s", str);
word = strtok(str," ");
printf("%s\n", word);
while(word != NULL)
{
word = strtok(NULL," ");
printf("%s\n", word);
}
//Second Line
fgets(str, 100, stdin);
printf("%s", str);
word = strtok(str," ");
printf("%s\n", word);
while(word != NULL)
{
word = strtok(NULL," ");
printf("%s\n", word);
}
return 0;
}