title: Reading data from stdin in C
body: <p>I'm trying to read from <code>stdin</code> and output the data, things work, EXCEPT that it's not outputting the <em>new incoming data</em>. I'm not quite sure where is the issue. I'm guessing it has something to do when determining the <code>stdin</code> size. Any help would be greatly appreciated! Thanks</p>
  
  <pre><code>tail -f file | my_prog
  </code></pre>
  
  <h2>Updated</h2>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/stat.h&gt;
  
  long size(FILE *st_in) {
      struct stat st;
      if (fstat(fileno(st_in), &amp;st) == 0)
          return st.st_size;
      return -1;
  }
  
  int main (){
     FILE *file = stdin;
     char line [ 128 ];  
  
     while ( fgets ( line, sizeof line, file ) != NULL )
        fputs ( line, stdout ); /* write the line */
  
     long s1, s2; 
     s1 = size(file);
     for (;;) {
        s2 = size (file);
        if (s2 != s1) {
           if (!fseek (file, s1, SEEK_SET)) {
              while ( fgets ( line, sizeof line, file ) != NULL ) { 
                 fputs ( line, stdout ); /* write the line */
              }   
           }   
           s1 = s2; 
           usleep(300000);
        }   
     }   
     return 0;
  }
  </code></pre>
  
  <p><strong>Edit</strong>: Fixed!</p>