Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion



Computer Science

Ankit 's Avatar
Blazing goIITian

Joined: 17 Oct 2007
Post: 1659
8 Jun 2009 22:37:57 IST
0 People liked this
3
902 View Post
c++ program to search a word in txt file
None

 The thing is I want to create a c++ program which will ask the user to input a word and the program will search the word in the text file and count no of times it occurs.Can anyone provide coding for that or any function which could be useful ?


Share this article on:

Comments (3)

anchal singhal's Avatar

Blazing goIITian

Joined: 21 Aug 2008
Posts: 380
8 Jun 2009 22:46:25 IST
0 people liked this

i think it can be done as--first input the word then apply for loop for the string and apply condition if(string[i]==word)then count++;it will give the no. of times the word has occured
AJ's Avatar

Blazing goIITian

Joined: 16 Apr 2009
Posts: 802
8 Jun 2009 22:51:15 IST
0 people liked this

anchal is right but take care to open the file in text mode.

Ankit 's Avatar

Blazing goIITian

Joined: 17 Oct 2007
Posts: 1659
8 Jun 2009 22:53:48 IST
0 people liked this

 though it not completely correct but it gives me some idea..we need to start the loop of both variables word as well as string at same time.

My problem is I am making a list of organic reactions ...ok so I will ask the user to input the name of any one reactants and my program will give the possbile  products so for that I will need to compare the input word many times and it needs to give output different too..counting was for general actually no need for my program




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads