Solution Found!
Word Count. A common utility on UniX/Linux systems is a small program called ''we." This
Chapter 5, Problem 14(choose chapter or problem)
Word Count. A common utility on UniX/Linux systems is a small program called ''we." This program analyzes a file to determine the number of lines, words, and characters contained therein. Write your own version of we. The program should accept a file name as input and then print three numbers showing the count of lines, words, and characters in the file.
Questions & Answers
QUESTION:
Word Count. A common utility on UniX/Linux systems is a small program called ''we." This program analyzes a file to determine the number of lines, words, and characters contained therein. Write your own version of we. The program should accept a file name as input and then print three numbers showing the count of lines, words, and characters in the file.
ANSWER:Step 1 of 3
The program can be written as follows:
1. Read the filename from the user.
2. Open file in ‘r’ mode.
3. For each line:
a. Add 1 to count line –num_lines.
b. Add count of words in line to – num_words.
c. Add count of characters in line to- num_chars.
4. Print count of lines, words, and characters.