become expert | help | login
refer a friend - earn nickels!!
 advanced

  Ask & Discuss Questions with Community & Experts

Moderation Team
  500 chars left
Ask community Community Discussion Question: c++ program to search a word in txt file
Reply Forum Index -> Computer Science originally posted here on IIT-JEE / AIEEE community   
Email  
Author Message
Ankit (2244)

Blazing goCBSEian

Olaaa!! Perrrfect answer. 366  [573 rates]

Ankit 's Avatar

total posts: 1660    
Offline

 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 ?


Only change is eternal.




    

Confused about NTSE Prep? Discuss with counselor! Book Session NOW! »      advertisement

anchal singhal (155)

Blazing goCBSEian

Olaaa!! Perrrfect answer. 25  [40 rates]

anchal singhal's Avatar

total posts: 380    
Offline
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
  this reply:   0 points  (with Olaaa!! Perrrfect answer.   in 0   votes   )     [?]
 
You have to be logged on to rate
  

Confused about NTSE Prep? Discuss with counselor! Book Session NOW! »      advertisement

AJ (243)

Blazing goCBSEian

Olaaa!! Perrrfect answer. 37  [66 rates]

AJ's Avatar

total posts: 802    
Offline

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

  this reply:   0 points  (with Olaaa!! Perrrfect answer.   in 0   votes   )     [?]
 
You have to be logged on to rate
  

Confused about NTSE Prep? Discuss with counselor! Book Session NOW! »      advertisement

Ankit (2244)

Blazing goCBSEian

Olaaa!! Perrrfect answer. 366  [573 rates]

Ankit 's Avatar

total posts: 1660    
Offline

 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


Only change is eternal.




  this reply:   0 points  (with Olaaa!! Perrrfect answer.   in 0   votes   )     [?]
 
You have to be logged on to rate
  

Confused about NTSE Prep? Discuss with counselor! Book Session NOW! »      advertisement

 
reply Forum Index -> Computer Science
Go to: 
Sponsored Links