int main() {
int n, i;
for (i = 0; i < 5; ++i) {
printf ("enter a single digit or hit enter \n");
scanf(" %d", &n);
if (n == EOF)
break;
printf("%d\n", n);
}
return 0;
}
On success scanf returns the number of fields successfully converted and assigned (1 in your case).
So any unusual condition (i/o error, EOF etc) test is:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.