Re: [algogeeks] Scanf in an infinite loop

2011-09-13 Thread Raghu Sarangapani
I modified your program as below. Every time, value of ret = 0. scanf is repeatedly failing cos there is some junk in the input stream Hence it prints junk values #include void main() { while(1) { int opt, ret; ret=scanf("%d",&opt); printf("opt is %d\n",opt);

Re: [algogeeks] Scanf in an infinite loop

2011-09-13 Thread shady
anyone ? very curious to know the answer On Tue, Sep 13, 2011 at 3:53 PM, Avinash Dharan wrote: > #include > void main() > { > while(1) > { > int opt; > scanf("%d",&opt); >printf("%d\n",opt); >} > } > > when i execute this program, if i give a character

[algogeeks] Scanf in an infinite loop

2011-09-13 Thread Avinash Dharan
#include void main() { while(1) { int opt; scanf("%d",&opt); printf("%d\n",opt); } } when i execute this program, if i give a character instead of an integer, it goes into an infinite loop. why is it so? -- You received this message because you are subscribe