Write a c program that counts the number of words and characters in a file. The program should do the following: Asks the user to input the name of the file to be opened. Display the contents of the file. Counts and displays the number of words and characters in a file. Exclude the spaces in the character count. Create a new file named “
Write a
Write a c program that counts the number of words and characters in a file. The program should do the following:
- Asks the user to input the name of the file to be opened.
- Display the contents of the file.
- Counts and displays the number of words and characters in a file. Exclude the spaces in the character count.
- Create a new file named “<inputted_file_name>_wordcharct.txt”, e.g. if the file name inputted in part a is “test.txt” then the file created should be named “test_wordcharct.txt”. Store the displayed information in this file
Expected output:
Sample 1:
Input the file name to be opened: test.txt
The content of the file “test.txt” are:
test line 1
test line 2
test line 3
test line 4
-----End of File----
The number of words in the file “test.txt” are: 12
The number of characters in the file “test.txt” are: 36
The file “test_wordcharct.txt” containing the results was
created successfully!
Sample 2: (use this one in creating the program)
Input the file name to be opened: aesop_fable.txt
The content of the file “aesop_fable.txt” are:
THE YOUNG CRAB AND HIS MOTHER
“Why in the world do you walk sideways like that?” said a Mother Crab to her son. “You should always walk straight forward with your toes turned out.”
“Show me how to walk, mother dear,” answered the little Crab obediently, “I want to learn.”
So the old Crab tried and tried to walk straight forward. But she could walk sideways only, like her son. And when she wanted to turn her toes out she tripped and fell on her nose.Do not tell others how to act unless you can set a good example.
-----End of File----
The number of words in the file “aesop_fable.txt” are: 100
The number of characters in the file “aesop_fable.txt” are: 419
The file “aesop_fable_wordcharct.txt” containing the results was created successfully!
Step by step
Solved in 2 steps with 1 images