title: Read from pipe line by line in C
body: <p>How can I separate the lines which are coming from a pipe. In the pipe there is this text:</p>
  
  <pre><code>HALLO:500\n
  TEST:300\N
  ADAD
  ADAWFFA
  AFAGAGAEG
  </code></pre>
  
  <p>I want to separate the lines from the pipe because i want to save the values in variables.</p>
  
  <p>Here is my c code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define BUFFERSIZE    1
  
  int main(int argc, char **argv){
      unsigned char     buffer[BUFFERSIZE];
      FILE                         *instream;
      int                            bytes_read=0;
      int                            buffer_size=0;
  
  
      buffer_size=sizeof(unsigned char)*BUFFERSIZE;
      /* open stdin for reading */
      instream=fopen("/dev/stdin","r");
  
      /* did it open? */
      if(instream!=NULL){
          /* read from stdin until it's end */
          while((bytes_read=fread(&amp;buffer, buffer_size, 1, instream))==buffer_size){
              fprintf(stdout, "%c", buffer[0]);
          }
      }
      /* if any error occured, exit with an error message */
      else{
          fprintf(stderr, "ERROR opening stdin. aborting.\n");
          exit(1);
      }
  
      return(0);
  }
  </code></pre>
  
  <p>Is this the right way to read from pipe for the best line by line?</p>