Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 4. PC #6. File Letter Counter (page 264) Write a program that asks the user to enter the name of a file, and then

Chapter 4. PC #6. File Letter Counter (page 264)

Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file.

Class name: FileLetterCounter

Hints:

Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0.

Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop.

I wrote the code but i can't make the character counter part work.

Required Output

Please enter the file name or type QUIT to exit: Please enter a character: Letter 'o' occurs 4 times in the file 'input.txt'. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

4. Describe cultural differences that influence perception

Answered: 1 week ago