title: How to solve this gets() function problem?
body: <p>In my program if I use <code>scanf()</code>, the program works fine. But as it is obvious, <code>scanf()</code> stops reading the input if it encounters a whitespace. So, instead I used <code>gets()</code>. But the problem is I have to use <code>gets(name[i]);</code> twice. If I use it only once, it skips the 'Subject Name' input &amp; jumps to 'Grade' input.</p>
  <p>Can you tell me where the problem lies?
  Here is the code, I removed almost all irrelevant parts.</p>
  <pre><code>#include &lt;ctype.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  void selection1();
  
  int main()
  {
      int op;
  
      printf(&quot;\n\t\t\t\t\t\t\t\tCHOOSE A NUMBER FROM 0 to 4: &quot;);
      scanf(&quot;%d&quot;, &amp;op);
      switch(op)
      {
      case 0:
          exit(0);
          break;
      case 1:
          selection1();
          break;
      case 2:
          //selection2();
          break;
      case 3:
          //selection3();
          break;
      case 4:
          //selection4();
          break;
      default:
          printf(&quot;\t\t\t\t\t\t\t\tInvalid Selection!!!\n&quot;);
          break;
      }
      return 0;
  }
  
  void selection1()
  {
      char name[20][50], grade[20][5];
      double credit[20][2];
      int i=0;
  
      for(;;)
      {
          printf(&quot;\t\t\t\t\t\t\t\tEnter Subject Name: &quot;);
          gets(name[i]);
          //gets(name[i]);
          printf(&quot;\t\t\t\t\t\t\t\tEnter Grade: &quot;);
          scanf(&quot;%s&quot;, &amp;grade[i]);
          printf(&quot;\t\t\t\t\t\t\t\tEnter The Course Credits: &quot;);
          scanf(&quot;%lf&quot;, &amp;credit[i]);
      }
  }
  </code></pre>