I have a text file and I should display its content using pipe in a C program. I have made something like this but isn't exactly what I need.
#include <unistd.h>
#define MSGSIZE 16
char msg1 = "hello, world #1";
char msg2 = "hello, world #2";
char *msg3 = "hello, world #3";
int main() {
char inbuf[MSGSIZE];
int p[2], i;
if (pipe(p) < 0)
exit(1);
/* continued /
/ write pipe */
write(p[1], msg1, MSGSIZE);
write(p[1], msg2, MSGSIZE);
write(p[1], msg3, MSGSIZE);
for (i = 0; i < 3; i++) {
/* read pipe */
read(p[0], inbuf, MSGSIZE);
printf("% s\n", inbuf);
}
return 0;
}
Here I gave the messages that I want to display. I really do not know how to do it for a file.