Write a program which given an input text file, computes and prints1 the number of characters in the

Page 1

Write a program which given an input text file, computes and prints:1. the number of characters in the file2. the number of words in the file3 To Purchase This Material Click below Link http://www.tutorialoutlet.com/all-miscellaneous/write-a-program-which-given-aninput-text-file-computes-and-prints-1-the-number-of-characters-in-the-file2-thenumber-of-words-in-the-file3 FOR MORE CLASSES VISIT tutorialoutlet

a) Write a program which given an input text file, computes and prints:1. the number of characters in the file2. the number of words in the file3. the number of lines in the file.The input file name is specified in the program.Your program should print zeros if the input file does not exist.(Hints: To count the number of lines, it is enough to count the number of ’n’characters.To count the number of words, it is not enough to count the number of ’ ’ charactersas the file may contain consecutive blank characters. One way to compute the numberof words is to loop till the end of the file while reading words into a temporaryC-string (array of characters) (using a suitable function that ignores white spaces)and incrementing a counter). b) Modify your program to allow the user the enter the input file name. Store the filename in a “C-string”, i.e., a ’’-terminated char array.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.