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 “

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a Program in C
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:

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!

 

Expert Solution
steps

Step by step

Solved in 2 steps with 1 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-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY