In this assignment, you will write a program that includes a parent process and
ID: 3910260 • Letter: I
Question
In this assignment, you will write a program that includes a parent process and a child process will read a word from standard input and send it to the child first line of a poem that contains the word. If the word is not in any line of the poem, the child process will print a message. The poem is read from a file whose name is provided as a program parameter process. The parent process. The child process will print the argy[!I) I. General Requirements Your programs' implementation must include the following features: The program starts by reading the poem from a file. The name of the file is given as a parameter. If the filename is wrong or the file cannot be opened, the program prints an error message and exits. The program then creates a pipe (named or unnamed) that the parent and child processes use t communicate. If the pipe cannot be created properly, the program prints an error message and exits. . The program will create a child process. After that, the parent and the child processes run concurrently The parent process keeps reading a word from the standard input and writes the word to the pipe. The parent process exits when the word is "quit The child process will read a word from the pipe and search for the word in the poem. If the word is not in the poem, it prints a message that the word is not found. Otherwise, it prints the first line where the word appears in the poem. o o Your submission must include a Makefile which includes rules to compile your program. A sample run may look like this: . . turing2 :-/Documents/Assign6% more poen.txt Time flies, and memories fade People change and new friendships are made. only the true remain forever at our side Eventually the disappointment and pain will subside. It is al1 about the journey and what has yet to come. Life is what you make of it you are what you've become Forgiveness is key even though you may never forget is too short to hold onto regrets. turing2 : ~/Documents/Assign6% ./a.out poen. txt what what is found: It is all about the journey and what has yet to come. key key is found: Forgiveness is key even though you may never forget. my my is not found rose rose is not found t is found: only the true remain forever at our side. quit turing2:~/Documents/Assign6% You may use any systems or tools to create and run your program. However, your program must run correctly on a departmental Linux computer Please follow the guidelines in the programming guideline document.Explanation / Answer
Program name is poem
#inlcude<stdio.h>
#inlcude<conio.h>
main()
{
FILE *fp;
char ch;
int i;
char quit;
printf(" 1. Chield Communication with File ");
printf(" 2. Parant Communication with File ");
printf(" 3. Quit ");
printf("Enter your Choice :-> ");
scanf("%i",i);
switch(i)
{
case 1:
{
fp = fopen("Poem.txt", "r");
while((ch=getc()) != EOF)
printf("%c",ch);
/* Print the file from chield
fclose(fp);
}
case 2:
{
fp = fopen("Poem.txt","w");
if(fp == NULL)
{
printf("File does not exists ");
}
printf("Enter Data ");
while( (ch = getchar()) != EOF)
{
putc(ch,fp);
if(ch=="quit")
{
exit;
}
}
}
case 3: exit;
case defalut: printf(" Input Invalid Number ");
}
fclose(fp);
}