Word Count. A common utility on UniX/Linux systems is a small program called ''we." This

Chapter 5, Problem 14

(choose chapter or problem)

Get Unlimited 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.

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.

Add to cart


Study Tools You Might Need

Not The Solution You Need? Search for Your Answer Here:

×

Login

Login or Sign up for access to all of our study tools and educational content!

Forgot password?
Register Now

×

Register

Sign up for access to all content on our site!

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back