Question
Input Use input redirection to provide input to your program from a file. Remember that scanf() reads from stdin, and we can change stdin by
Input
Use input redirection to provide input to your program from a file. Remember that scanf() reads from stdin, and we can change stdin by using the following run command: ./program < input_filename. It is also recommended to use output redirection to verify whitespaces: ./program < input_filename > output_filename.
In the input file, the first line will only contain one word, which is the word to be deleted. The remainder of the file (the second line to the end of the file) will be the input text. There will be no empty lines in the file (aside from the newline at the end of the file). Each line will contain one or more words. A word is defined as any characters between whitespace. Each word will be separated by one space, and the line will not have any leading or trailing spaces.
Example input file:
cs // word to be deleted
cs hello there // start of input text lines
hello there cs
cs
hello cscs there cs.
cs cs cs
test
The line " this is an invalid line " is invalid input, as it has a leading space and a trailing space, which are both invalid.
There will be one whitespace char (space or newline) between each word in the input text. For example, the text "I love computer science." represents the four words: "I", "love", "computer", and "science.". Any non-whitespace is included in the word. If a number or symbol is in the input text, it also counts as part of the word. For example, "I love CS 100 class." represents the five words "I", "love", "CS", "100", and "class.".
Delete
If the word to be deleted is found in the text, it needs to be removed. The word is case-sensitive. "word" is not the same as "word.", which is not the same as "Word". After deleting the word, delete any extra whitespace that violate the rules outlined above (1 space between words). If deleting the word (and any spaces) results in an empty line, do not print the empty line.
Output
You will need to output:
The number of words in the input text
The number of words removed
The new text
Match the output of the examples below exactly. Whitespace is checked in this project. Be sure to submit to the tester project to verify whitespace.
Notes
Do not forget to have the empty newline at the end of the input file. Also, be sure the input files have an end-of-line-sequence of LF and not CRLF. You can change the end-of-line-sequence of a file in VS Code by looking at the status bar in the bottom right of the window and clicking the LF/CRLF and selecting LF.
All words will be less than 50 chars.
Each line will be less than 200 chars.
The total text will be less than 1,000 chars.
Do not forget to terminate strings with the null terminator '\0'.
Do not forget that fgets(str, size, stdin), which reads an entire line, includes the newline char ' ' in the destination string (if you choose to use it).
Example
% cat example1.txt
word Delete the word from this line.
% gcc p3.c -o p3 % ./p3
< example1.txt
--NEW TEXT--
Delete the from this line.
--STATS--
Number of words in the original text: 6
Number of words removed: 1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started