title: C : How to check end of input from keyboard or file while using scanf one char at a time
body: <p>I have to write a program  in C for class that reads in one character at a time and we have to use scanf. I got it to work with input from only the keyboard however, my teacher will be testing the code with file redirection as well.</p>
  
  <pre><code>int end;                                    //return value of scanf
  int length1;                                //length of string exp1
  char temp,                                  //temp char for input
  char exp1[81];                              //string
  
  printf ("Please enter in a regular expression:\n");
  end = scanf ("%c", &amp;temp);
  
  while (temp != '\n' || end == 1) {          //check if end of input
     length1 = check(temp, length1, exp1);    //returns length of exp1
  
     end = scanf ("%c", &amp;temp);               //scan next char for loop
  }
  </code></pre>
  
  <p>I've been at this one tiny problem for hours trying to figure it out so any pointers are helpful. Thanks!</p>
  
  <p>EDIT: I've tried using the kbhit() function in an if statement to check if they typed in the input or if the input is from a file. However, I don't have conio.h, is there any alternative while still using scanf?</p>