title: How to read from named pipe in C?
body: <p>I am trying to code a Named pipe in linux in C</p>
  
  <p>I searched and searched but still could not find how to properly read from a named pipe. though my code looks ok.</p>
  
  <p>The writing to the pipe works.<br>
  But reading is stuck in an infinite loop. The behaviour is very strange.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;fcntl.h&gt;
  #include&lt;sys/types.h&gt;
  #include&lt;string.h&gt;
  
  struct letter
  {
      char name[10];  
      float val;
  }temp;
  float a,b;
  int fd;
  
  main()
  {
      int choice; 
      mkfifo("testfifo",0666);
      fd=open("testfifo",O_RDWR);
  
      printf("Input value of A ");
      scanf("%f",&amp;a);
      printf("Input value of B ");
      scanf("%f",&amp;b);
      write_to_fifo();
      close(fd);
  
      printf("Evaluate?");
      scanf("%d",&amp;choice);
      fd=open("testfifo",O_RDWR);
      evaluate();
  }
  write_to_fifo()
  {
      temp.val=a*b;
      strcpy(temp.name,"temp1");
      write(fd,temp,sizeof(temp));
  }
  evaluate()
  {
      float prod; 
      read(fd,temp,sizeof(temp));
      prod=temp.val;
      printf("Result is %f",prod);
  }
  </code></pre>