I'm new to C and currently doing homework that happens to deal with scanf()
The second scanf()
is being ignored after I hit Ctrl+d
twice to exist the first scanf()
and I can't figure out why does that happen. In the debugger, I can see that the program skips the second scanf()
. Is it because something like, Ctrl+d
ends the input buffer so the second scanf()
does not get a chance to read anything from the input. I am not professional at using technical terms so my description might be kinda vague.
Thanks for any help in advance.
int main(int argc, const char * argv[]) {
NODE *list = NULL;
while (1) {
char *word = malloc(101);
if (scanf("%s", word) == EOF) {
break;
}
push(word, &list);
//free(word);
}
int index[3];
for (int i = 0; i < 3; i++) {
scanf("%d", &index[0]);
}
pop(index[0], &list);
pop(index[1], &list);
pop(index[2], &list);
printList(list);
free(list);
return 0;
}