title: Gets/fgets jumped over steps of input in C
body: <p>I have an exercise that I need to create a program to input all information of students as a student report as the source code below. I have a problem that I can't get a full stream input. It stepped over grade input and jumped to another student to input the next student's ID. I have put <code>getchar()</code> to get <code>\n</code> but it does not help. My problem is in the case 1 of the switch, so you just need to care only about it, the other cases do not make any sense in my question.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX 1000
  typedef struct 
  {
      char id[10];
      char name[50];
      float grade;
      char assess;
  }student;
  char assess(int a)
  {
      if(a&lt;4.00)
      return 'F';
      if(4.00&lt;=a&lt;6.00)
      return 'D';
      if(6.00&lt;=a&lt;7.00)
      return 'C';
      if(7.00&lt;=a&lt;8.50)
      return 'B';
      if(8.50&lt;=a&lt;10.00)
      return 'A';
  }
  int main()
  {
      int choice;
      int i=0, num=0; 
      int a=0, j=0;
      student std[MAX], temp;
      char search[50];
      do
      {
          printf("Student Report\n");
          printf("1.Input data\n2.Append data\n3.Sort data and print\n4.Search by names5.Quit\n");
          printf("Your choice is: ");
          scanf("%d", &amp;choice);
          switch(choice)
        {
              case 1:
              {
                  do{
                  printf("How many students you want to add?\n");
                  scanf("%d", &amp;num);
                  if(num&lt;0 || num&gt;50)
                  printf("Your number must be positive or smaller than or equal to 50!\n");
                  }while(num&lt;0||num&gt;50);
                  for(i=a; i&lt;num; i++)
                  {
                      printf("Student's id No.%d:", i);
                      fgets(std[i].id, 10, stdin);
                      getchar();
                      printf("Student's name No.%d:", i);
                      fgets(std[i].name, 50, stdin);
                      getchar();
                      printf("Student's grade No.%d:", i);
                      scanf("%f", &amp;std[i].grade);
                      std[i].assess=assess(std[i].grade);
                  }
                  a=num;
              }
              case 2:
              {
                  do
          {
            printf("How many students you want to append?[0; %d]\n", MAX-num);
            scanf("%d", &amp;num);
                  }while(num&lt;0||num&gt;50-a);
                  for(i=a; i&lt;num+a; i++)
                  {
                      printf("Student's id No.%d:", i);
                      fgets(std[i].id, MAX, stdin);
                      getchar();
                      printf("Student's name No.%d:", i);
                      fgets(std[i].name, MAX, stdin);
                      getchar();
                      printf("Student's grade No.%d:", i);
                      do
              {
                scanf("%f", &amp;std[i].grade);
                if(std[i].grade&lt;0||std[i].grade&gt;10)
              printf("Please re-input grade, it must be between 0 and 10\n");
                      }while(std[i].grade&lt;0||std[i].grade&gt;10);
                      std[i].assess=assess(std[i].grade);
                  }
                  a=num+a;
              }
              case 3: 
              {
                  for(i=0; i&lt;a; i++)
                  for(j=0; j&lt;a; j++)
                  {
                      if(std[i].grade&lt;std[j].grade)
                      {
                          temp=std[i];
                          std[i]=std[j];
                          std[j]=temp;
                      }
                  }
                  printf("ID\tName\t\t\tGrade\t\tAssessment\n");
                  for(i=0; i&lt;a; i++)
                  printf("%-10s%-50s%-10.2f%-10c\n", std[i].id, std[i].name, std[i].grade, std[i].assess);
              }
              case 4:
              {
                  printf("Student's name who you want to search: ");
                  fgets(search, MAX, stdin);
                  getchar();
                  for(i=0; i&lt;a; i++)
                  if(strcasecmp(search, std[i].name)==0)
                  printf("%-10s%-50s%-10.2f%-10c\n", std[i].id, std[i].name, std[i].grade, std[i].assess);
              }
              case 5:
              break;
              default:
              {
                  printf("Please reinsert your choice again\n");
                  break;
          }
        }
      }while(choice!=5);
      return 0;
  }
  </code></pre>