Question: 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

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!