Coders Packet

Word/Character Counter Using C++

By DEVADHARSHINI M

In this project, a valid text file name is given by the user, and the count of words/characters in the file is found out using C++ Programming Language.

First, we start up by including all the header files needed.

In the main function, create all the needed variables with their specified types.

Using cout and cin, get the file name and store that file name in a variable. The file name should be given with the file's extension type.

filename wc

Here is a sample text file created using Notepad with the name code_speedy.txt

Using the built-in 'ifstream' class, open the given file name and store its contents in another variable.

Next, the user should give what number of count does she/he wants.

After selecting the correct option, the needed result would be satisfied.

If the user gives an invalid file name/option, the next steps that should be followed on, gets terminated.

(NOTE : If we want to get the count of a file's content, which is outside the project's folder, please specify the path of the folder while giving in the file name, so that the compiler can understand that the path of file is outside the project's folder. If this is not done, the compiler cannot identify the path outside the project's folder, where it assumes it as an invalid file name.)

Download Complete Code

Comments

No comments yet