I am trying to code a Named pipe in linux in C
I searched and searched but still could not find how to properly read from a named pipe. though my code looks ok.
The writing to the pipe works.
But reading is stuck in an infinite loop. The behaviour is very strange.
#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<string.h>
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",&a);
    printf("Input value of B ");
    scanf("%f",&b);
    write_to_fifo();
    close(fd);
    printf("Evaluate?");
    scanf("%d",&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);
}