title: scanf function is skipping input in for loop in C Programming
body: <p>I have write simple code using structure method and in that code I am taking string(name) as input using for loop for 3 students. For 1st iteration each line in for loop is working as it should be.... but problem comes on second iteration... in second iteration <code>scanf</code> is skipping input for string (name)...</p>
  
  <p>My code is as below :</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  struct student_data
  {
      char name[5];
      int dsd;
      int dic;
      int total;  
  };
  
  void main()
  {
      struct student_data s[3];
  
  
      int i;
  
      for(i = 0;i&lt;3;i++)
      {
          printf("Enter Name of Student\n");
          scanf("%[^\n]",s[i].name);         // Problem occures here in     
                                         //  second iteration  
  
          printf("\nEnter marks of DSD\n");
          scanf("%d",&amp;s[i].dsd);
  
          printf("Enter marks of DIC\n");
          scanf("%d",&amp;s[i].dic);
  
  
          s[i].total = s[i].dsd+s[i].dic;     
  
      }
  
      printf("%-10s %7s %7s  %7s\n ","Name","DSD","DIC","Total");
      for(i=0;i&lt;3;i++)
      {
  
         printf("%-10s %5d  %6d      %6d\n",s[i].name,s[i].dsd,s[i].dic,s[i].total);
  }  
  </code></pre>
  
  <p>}</p>