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 “_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: 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!
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:
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!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps