I've never been sure about how EOF works on a system. Take for instance this example program, which counts strings entered until it encounters the word "quit" or the EOF.
Then the following expected behavior is given:Code:#include <stdio.h> #include <string.h> #define SIZE 81 #define LIM 100 #define STOP "quit" int main(void) { char input[LIM][SIZE]; int ct = 0; printf("Enter up to %d lines (type quit to quit):\n", LIM); while (ct < LIM && gets(input[ct]) != NULL && strcmp(input[ct], STOP) != 0) ct++; printf("%d strings entered\n", ct); return 0; }
But what is happening here?1
2
3
4
5
^Z
5 strings entered
And here?1
2
3
4
5^Z
^Z
^Z
5 strings entered
1
2
3
4
5^Z
6
7
8
9
^Z
8 strings entered



LinkBack URL
About LinkBacks


