title: C - Create/Write/Read named pipe
body: <p>I want to create a named pipe and then write to it and after that I want read it. Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fcntl.h&gt;
  #define FIFO "fifo0001"
  int main(intargc, char *argv[]){
      char input[256];
      FILE *fp;
      char str[50];
      printf("Please write some text:\n");
      scanf("%s", input);
      unlink(FIFO); /* Because it already exists, unlink it before */
      umask(0);
      if(mkfifo(FIFO, 0666) == -1){
          printf("Something went wrong");
          return EXIT_FAILURE;
      }
      if((fp = fopen(FIFO, "a")) == NULL){
          printf("Something went wrong");
          return EXIT_FAILURE;
      }
      fprintf(fp, "%s", input);
      if(fgets(str, 50, fp) != NULL){
          puts(str);
      }
      fclose(fp);
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>After I write a text, nothing happen anymore. And there is no message. I have to quit the program with STRG C. Someone know what is wrong? I have to use the functions mkfifo, fopen, fprintf, fgets and fclose. So would be nice if I could keep them into the code.</p>