I tested with this program:
Code:
#include <stdio.h>
int main(void)
{
int i = 0;
int j;
int del[10000];
while (i < 10000 && scanf("%d", &del[i]) == 1)
{
i++;
}
printf("These are the entries:\n");
for (j = 0; j < i; ++j)
{
printf("%d\n", del[j]);
}
printf("Total of %d entries.\n", i);
return 0;
}
Entering this input followed by triggering EOF:
I received this output:
Code:
These are the entries:
1
2
3
4
5
6
7
Total of 7 entries.
EDIT:
Originally Posted by
Snowflake
if I use your code is EOF going to be active?
EOF means "end of file". If the end of file has been reached, then there will not be any more input from that input stream, so when you attempt to read with scanf, you will get EOF (the value, not the condition) returned. EOF != 1, so the loop will end. While you could compare with EOF instead of 1, with more complex format strings that might be undesirable, or it might even be possible for scanf to return 0.