Reputation:
I have a while loop that scans in an input set of integers. It scans and prints all of the numbers with "..." at the end and skips to the next line. However, the script does not: execute past the while loop and print TEST.
For example, I enter: 3 44 62 1
It prints: 3...
44...
62...
1...
When it should print: 3...
44...
62...
1...
TEST
while(scanf("%d", &n) != -1) {
x[i] = n;
i++;
printf("%d", n);
printf("...\n");
}
printf("TEST");
What am I doing wrong?
Upvotes: 0
Views: 5745
Reputation: 85767
scanf("%d", &n) != 1
is wrong. It should be scanf("%d", &n) == 1
.EOF
being -1; it's not portable.)Upvotes: 6