EmbLogic's Blog

what does the following code do..??

while((c=getchar())==’\n’);

NOTE that there is a semicolon at the end.

4 Responses to what does the following code do..??

  1. kamran says:

    the while statement will be executed only once.

  2. sheetal sharma says:

    while is executed until condition is true but there is no statement in while because of semicolon so that it only takes input and compare it with ‘\n’ if condition is true loop is continue otherwise it break.

  3. Manoj says:

    the actual problem was found with switch. if i use choise as an integer variable but press a character instead of integer at the time of making choise… it will go to default but also will move to infinite loop.
    to solve that I had to use the code given above… but I am still not able to understand the significance of using this line…@sheetal if I entered hello\n(Enter) then, how will it be treated..??

    • sheetal sharma says:

      switch goes infinite because there is some characters in stdin stream that is taken by scanf() this problem can be solved if you clear the input stream.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>