c - Expected program to print the value of EOF -
in code:
#include<stdio.h> int main() { int t; for(;scanf("%d",&t);printf("%d",t)); }
the program runs expected when give general intergers input. working on windows when scanf cntrl+z argument t, not value of eof i.e -1 on standard output, previous argument stored in it. when press cntrl + d program terminates, why cntrl+d cause scanf return 0?
and why on scanf cntrl+c compiler says: "process terminated status -107......" not understanding why happening? please help.
scanf
returns number of matched formatting specifiers, or eof
if end of input reached before matching (or failing match) first specifier.
when press ctrl+z, scanf
reaches end of input , returns eof (because ctrl+z terminates input on windows). not terminate for
loop because eof
nonzero, previous value of t
printed (as t
not changed call). note t
not receive value eof
on end-of-input seem expect: scanf
returns eof
return value, not write pointers pass it.
when press ctrl+d, treated other character. since non-numeric, causes matching failure %d
specifier , scanf
returns 0, terminates loop.
Comments
Post a Comment