My problem understanding the stream behaviour i was getting stemmed from one little peculiarity. I didnt know that in Windows console there is a newb unfriendly ambiguity , Ctrl+Z can be as read ASCII 0x1A if you enter input like 12 23 ^Z/enter/ but gets read as proper EOF, when you do 12 23 /enter/^Z/enter/. this code solves the issue
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("int or eof\n");
int num;
while( scanf("%d",&num) ==1 )
{
printf("the read number is %d \n",num);
}
if(!feof(stdin) && getchar()!=0x1A)//first check if its read as EOF,
//if it fails, call getchar for help to check for ^Z
{
printf("non-int error\n");
}
else printf("eof ok\n");
system("PAUSE");
return 0;
I am sorry for the misleading question.