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!

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 9PP: (Inventory) Create an ASCII file with the following data, or use the shipped.dat file available on...
icon
Related questions
Question

Write a C program that counts the number of words and characters in a file. The program should do the following:

  1. Asks the user to input the name of the file to be opened.
  2. Display the contents of the file.
  3. Counts and displays the number of words and characters in a file. Exclude the spaces in the character count.
  4. 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!

Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr