title: reading input with fgets(goes into endless loop)
body: <p>I have this application where it reads user input with fgets. It works fine and have no problem if I take user input while program is running. But if I feed a file say "./myprog &lt; in.txt", it goes into infinite loop and print my custom error message that I show when user doesn't provide valid input all over the screen. It's like return key is pressed. How do I solve that problem?</p>
  
  <p>This is one section of my program that's has fgets</p>
  
  <pre><code>while(1){
    mainMenu(&amp;choice);
    switch(choice)
    {
       case 0: 
          return 0;
  
       case 1: //Add movies 
          getMovieData(&amp;list);
          break;
  
       case 2:
          ....some initialization... 
          printf("Provide a name to delete : ");
          fgets(inputBuffer,sizeof(inputBuffer),stdin);
      trimWhiteSpace(inputBuffer);
          deleteMovie(&amp;list,inputBuffer);
          break;
  
       case 3: //List all movies
          printMovieData(list);
          break;
  
       case 4: //List movies by genre
          inputBuffer[0] = '\0';
          printf(".....");
      fgets(inputBuffer,sizeof(inputBuffer),stdin);               
          trimWhiteSpace(inputBuffer);
          if(!isNum(inputBuffer,&amp;genreChoice)){ 
             showMessage("Number Expected\n");
             break;
          }
          else if(!checkNumberValidity(&amp;genreChoice,1,6)){
             showMessage("Choose from 1 to 7\n");
             break;
          }
          else printMoviesByGenre(list,getGenre(genreChoice-1));
          break;
  
    }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>while(1){
    printf("Provide the number of movies you would like to enter: ");
    fgets(temp, sizeof(temp), stdin);
    trimWhiteSpace(temp);         
    if(!isNum(temp,&amp;numMovie)) printf("Enter a numeric value\n");
    else if(!checkNumberValidity(&amp;numMovie,1,MAX_MOVIES)) printf("No greater than %d\n",MAX_MOVIES);  
    else break;
  </code></pre>
  
  <p>}   </p>