Question

Write a program that communicates with its child process via two pipes, one being the "down pipe" for sending data from the parent to the child, and the other being the "up pipe" for sending data from the child to the parent. After creating the child process, the parent process must repeatedly read a line of text from the user, write the text to the down pipe for the child to read, read the child's reply from the up pipe, and output the reply to the screen.

The child process must redirect its standard input to come from the down pipe, and its standard output to go to the up pipe. The child must then loop, reading text from its standard input and echoing the text, prepended with "Bounced", to it's standard output. Of course, due to the redirection, the child is actually reading from the down pipe and writing to the up pipe. The code that the child must use for the loop is:

        while (fgets(Buffer,STRING_LENGTH,stdin) != NULL) {
            printf("Bounced %s",Buffer);
            fflush(stdout);
        }
Note the use of fflush to force the output into the pipe.

Answer