Question: In C , NO FILE POINTERS, Write a set of programs that transfers string data entered in one program to the other program over a
In C NO FILE POINTERS, Write a set of programs that transfers string data entered in one program to the other program over a FIFO.
The first program should prompt the user to enter words in a manner similar to the following:
Please enter text at the producer: prompt
producer:
The second program should then respond to receiving the data over the pipe by outputting
consumer:
Existing code:
producer.c:
#include stdio.h
#include stdlib.h
#include string.h
#include unistd.h
#include fcntlh
#include sysstath
#define FIFONAME "myfifo"
int main
char input;
Create the FIFO named pipe
mkfifoFIFONAME, ;
printfPlease enter text at the producer: ;
fflushstdout;
while
Get user input
fgetsinput sizeofinput stdin;
Open the FIFO for writing
int fd openFIFONAME, OWRONLY;
Write data to the FIFO
writefd input, strleninput;
closefd;
return ;
consumer.c:
#include stdio.h
#include stdlib.h
#include unistd.h
#include fcntlh
#include sysstath
#define FIFONAME "myfifo"
int main
char receiveddata;
Create the FIFO named pipe
mkfifoFIFONAME, ;
while
Open the FIFO for reading
int fd openFIFONAME, ORDONLY;
Read data from the FIFO
readfd receiveddata, sizeofreceiveddata;
closefd;
Display the received data
printfconsumer: s receiveddata;
return ;
The first program dosen't end after I entered text, the second program dosen't print anything.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
