How to end scanf by entering only one EOF
I am encoutering this problem. I am using while loop to scan string of numbers and need to end scanning and start proceeding the rest of my program. I just can't figure out, how to flush the stdin or do anything to not press Ctrl+D twice. I just need to send EOF only once to tell my loop to end. while (! feof (stdin)) {status=scanf ("%d", &array[i]); if ( (status != 1 && status != EOF) ) { printf("\nWrong input.\n"); return 1;} i++;} Edit: it's bug 1190 on glibc , it was apparently done purposefully for System V compatibility (and Solaris behaves in the same way, FreeBSD and NetBSD behave as