title: scanning until EOF in c
body: <p>I am writing a decryption program and I need to scan in an unknown number of strings and decode each string as it is entered.  The program must end once it reaches EOF.</p>
  
  <p>I am having difficulty getting the program to end.  when I scan in the first char in the string in my while loop condition statement, it is doing this but when I scan in the actual string bellow the condition statement the string is missing the first char. Should I scan in the first char and then somehow put that char at the beginning of the string?</p>
  
  <p><strong>How do I properly test for EOF in my situation?</strong>   </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  int main(void)
  {
      int i;
      char code[300];
  
      while(scanf("%c", &amp;code[0])!=EOF)
      {
          scanf("%s", code);
  
          for(i=0; i&lt;strlen(code); i++)
          {
              decrypt message one char at a time
          }
          printf("\n");
      }
      return 0;
  }
  </code></pre>