title: Loop over stdin in C
body: <p>I am trying to loop over stdin, but since we cannot know the length of stdin, I am not sure how to create the loop or what condition to use in it.</p>
  
  <p>Basically my program will be piped in some data. Each line in the data contains 10 characters of data, followed by a line break (So 11 characters per line)</p>
  
  <p>In pseudocode, what I am trying to accomplish is:</p>
  
  <pre><code>while stdin has data:
      read 11 characters from stdin
      save 10 of those characters in an array
      run some code processing the data
  endwhile
  </code></pre>
  
  <p>Each loop of the while loop rewrites the data into the same 10 bytes of data.</p>
  
  <p>So far, I have figured out that</p>
  
  <pre><code>char temp[11];
  read(0,temp,10);
  temp[10]='\0';
  printf("%s",temp);
  </code></pre>
  
  <p>will take the first 11 characters from stdin,and save it. The printf will later be replaced by more code that analyzes the data. But I don't know how to encapsulate this functionality in a loop that will process all my data from stdin.</p>
  
  <p>I have tried </p>
  
  <pre><code>while(!feof(stdin)){
      char temp[11];
      read(0,temp,11);
      temp[10]='\0';
      printf("%s\n",temp);
  }
  </code></pre>
  
  <p>but when this gets to the last line, it keeps repeatedly printing it out without terminating. Any guidance would be appreciated.</p>