title: while loop gets() twice in C
body: <p>I know that this while loop issue is very common, and it is usually caused by a newline in a input stream. However, I wasn't able to fix my while loop, and I don't really understand why it's happening in my case.</p>
  
  <p>Consider the following example:</p>
  
  <pre><code> int main()
   {
     int option = -1;
     char buffer[100];
     while (option != 10)
      {
       while(printf("Enter menu choice: \n"), gets(buffer), option &lt; 0)
             {
               some code here dealing with buffer and assigning input to option...
             }
       printf("something\n");
       }
      return 0;
    }
  </code></pre>
  
  <p>Ignore the implementation of this code (e.g store the input in integer instead of string, etc.) as it's just a simplified version of my case for while loop. What concerns me is then I have to enter the number twice before it actually goes through the loop.</p>
  
  <p>Output:</p>
  
  <p>Enter menu choice:
  1</p>
  
  <p>Enter menu choice:
  1</p>
  
  <p>All lights are turned on
  Light settings: 1111 1111 1111 1111</p>
  
  <p>I am not sure why it's happening in this case...Thanks!</p>
  
  <p>UPDATE: Thank you for your answers. I have fixed code by rewriting my while() condition</p>
  
  <pre><code>while(printf("\nEnter menu choice: \n"), gets(buffer),  option = checkMenuOption(buffer), option &lt; 0 &amp;&amp; strcmp(buffer, ""));
  </code></pre>