By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,742 Members | 1,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,742 IT Pros & Developers. It's quick & easy.

A C++ program for counting individual string in a text file using file handling

P: 1
A C++ program for counting individual string in a text file using file handling functions.,

for ex:

if the text file contains,

am a boy,am studying +2,am from chennai

Now the result shoud be as 3 bcaz ("am" presenting 3 times)
Sep 1 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 464
Are you wanting the total number of lines in the file? Is the text file
am a boy
am studying +2
am from chennai
(on 3 seperate lines)

you should look at fgets, and fopen functions
Sep 1 '07 #2

sicarie
Expert Mod 2.5K+
P: 4,677
Are you wanting the total number of lines in the file? Is the text file
am a boy
am studying +2
am from chennai
(on 3 seperate lines)

you should look at fgets, and fopen functions
I would recommend cplusplus.com. In their Documentation section, they have an excellent tutorial on both file streams (you are looking for a file input stream), as well as strings. I would recommend looking into getline() and strtok(). That way you can get an entire line from a file and find (specifically the next, but if you iterate until strtok() fails, then you have gotten all of the "tokens" such as 'am', on that line) all the values you were looking for.
Sep 1 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.