Question: In C, write a program called 'chaining' that does the following: 1. Prompts user for an input file. Assume the filename is less than 1000

In C, write a program called 'chaining' that does the following:

1. Prompts user for an input file. Assume the filename is less than 1000 chars. It will ask for a file by printing 'Enter an input file now: '.

2. Prompts user for the 1st command to run as a single input line. Assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the first command now: '.

3. Prompts user for the 2nd command to run as a single input line. Again, assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the second command now: '.

4. Prompts user for the 3rd command to run as a single input line. Assume the input line is less than 4000 chars. It will ask for the command by printing 'Enter the third command now: '.

5. Prompts user for an output file. Assume the filename is less than 1000 chars. It will ask for the file by printing 'Enter an output file now: '.

6. The program should then execute the 3 commands. The 1st command gets its input from the input file. The 1st commands input will be redirected to the input of the 2nd command. The 2nd commands input will be redirected to the input of the 3rd command. The 3rd commands output will go into the output file.

Note:

- The output file should not be appended to but replaced instead.

- Don't use the system() function call - use an exec call to run the commands.

Checking your program:

- Compare what happens if you run the following at the Linux/MacOS shell: first_command < input_file | second_command | third_command > output_file

- Example: cat < /etc/passwd | sort -t : -n | head -15 > sorted_beginning_of_etc_passwd.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!