title: How to loop a FIFO reader program in C
body: <p>I'm writing a c program in ubuntu that writes and reads in fifo pipe. I already have the program writing working perfectly, I now have a problem reading in a loop. </p>
  
  <p>My reading program :</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;errno.h&gt;
  
  #define MAX_CTRLS 80
  
  void main()
  {
  printf("test1");
     char ch2[MAX_CTRLS];
     int pipe1;
     pipe1 = open("/tmp/ctrl", O_RDONLY);
  printf("test2");
     read(pipe1, ch2, MAX_CTRLS);
     printf("%s",ch2);
    close(pipe1);
  }
  </code></pre>
  
  <p>This program is supposed to read in the fifo, store it in ch2 then print in ch2. But when running it normally it works perfectly, while running it in a loop, it doesn't do anything.</p>
  
  <p>Here is writing program 1 :</p>
  
  <pre><code>void send(char ch2[MAX_CTRLS])
  {
      int create;
      create = mkfifo("/tmp/ctrl", 0666);
      int pipe1;
      pipe1 = open("/tmp/ctrl", O_WRONLY);
      write(pipe1, ch2, MAX_CTRLS);
      close(pipe1);
  }
  </code></pre>
  
  <p>This one works using another program I have, that has a line like this :</p>
  
  <pre><code>ch2[0] = 'a';
  printf("%s",ch2);
  send(ch2);
  </code></pre>
  
  <p>The printf helps me confirm that ch2 is set properly. I need the reading program to loop the reading function, aka print everytime what is set in ch2.</p>
  
  <p>I just ant it to print a in this case, everytime my program launches send(ch2).</p>
  
  <p>Thaks in advance</p>