I had a ques related to the recent discussion we had on fast I/O…using that function how do we read EOF!!!
I had to start a new Thread as the earlier one was closed…pls dont mind…
I had a ques related to the recent discussion we had on fast I/O…using that function how do we read EOF!!!
I had to start a new Thread as the earlier one was closed…pls dont mind…
Modifying above answer :
//#include< stdio.h >
int readint()
{
int cc;
while( (cc = getchar()) && (cc < '0' || cc > '9') )
{
if(cc==EOF) return EOF;
}
int ret = 0;
while(cc >= '0' && cc <= '9')
{
ret = ret * 10 + cc - '0';
cc = getchar();
}
return ret;
}
int main()
{
int x;
while( (x = readint())!=EOF )
{
printf("%d\n",x) ;
}
}
how can i be sure that there are no more inputs???
should i add a counter of some sort to see if it exceeds a particular value MAX(say arnd 1000 iterations) break out the loop make a flag saying that no more ips and then return -1…and then in main check if the EOF flag is true or no???
In the i/o function initialize ret to some value out of range of inputs given in problem. For eg: set ret = INT_MAX. In main func check if(ret==INT_MAX) then break out of loop. Also you may use flags. For eg: In your problem 0<n<10000000 then set ret to 0 initially and if 0<=n<10000000 then set ret to -1 initially.
Yeah sure
ok…thanks a lot…