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 <stdio.h>
void main()
{
    while(1)
    {
        int opt, ret;
        ret=scanf("%d",&opt);
        printf("opt is %d\n",opt);
        printf("ret is %d\n",ret);
    }
}


Regards,
Raghu


On Tue, Sep 13, 2011 at 3:23 AM, Avinash Dharan <avinashdha...@gmail.com>wrote:

> #include <stdio.h>
> 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 subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to