title: EOF to redirect a file or taking input from stdin
body: <p>I have designed a parser with some state transitions. Now i want to redirect a file into my parser created in C to give the tokens.</p>
  
  <p>My design is such that I need a space(' ') at the end of my string, that is  , I need to append a space character to the string read from the file or stdin. But the problem is the indexing.
  For redirecting from a file i need to do</p>
  
  <pre><code>int length=0;
  
  while((c1=getchar())!=EOF)
  {
  a[length]=c1;
  length ++;
  }
  a[length-1]=' ';
  a[length]=EOF;
  </code></pre>
  
  <p>While for reading from stdin, i need to do</p>
  
  <pre><code>int length=0;
  while((c1=getchar())!=EOF)
  {
  a[length]=c1;
  length ++;
  }
  a[length]=' ';
  a[length+1]=EOF;
  </code></pre>
  
  <p>The input can come both from a stdin input or a file redirection(eg ./a.out &lt; a.c) Now how do I do incorporate if these in my code, based on the type of input???</p>