Search a txt file for words

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 3
Reputation: taha54 is an unknown quantity at this point 
Solved Threads: 0
taha54 taha54 is offline Offline
Newbie Poster

Search a txt file for words

 
0
  #1
Aug 16th, 2006
hi all , i have a txt file called myfile.txt , i want to open this file and search for the following
" this page is good/"

if i find this i want to read every thing after "/" until i reach <b> so for example

this page is good/so i want to copy this<b>

dont mind my question but i really dont know much in C++


thanks for your great help
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: taha54 is an unknown quantity at this point 
Solved Threads: 0
taha54 taha54 is offline Offline
Newbie Poster

Re: Search a txt file for words

 
0
  #2
Aug 16th, 2006
any help???
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: Search a txt file for words

 
0
  #3
Aug 16th, 2006
1. Open file
2. Retrieve data in a string
3. Compare
4. Once you find a match then read again till you find first <b>
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: taha54 is an unknown quantity at this point 
Solved Threads: 0
taha54 taha54 is offline Offline
Newbie Poster

Re: Search a txt file for words

 
0
  #4
Aug 16th, 2006
i need the code for that , i really dont know alot in C++
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: Search a txt file for words

 
1
  #5
Aug 16th, 2006
We really don't like to write whole programs or routines for people. Here's a quick overview with a little more detail than p;rovided by Grunt. As you can tell, there are several choices you will have to make depending on what you know and don't know.

The phrase you are looking for is called a string. The file you are searching can be opened and read in as a sequence of strings or as a single string. You will then need to search for the string(s) from the file for the desired string. If found, the desired string is called a substring of the whole string. There are several ways to search for a substring depending on the type of string you use. You could use strstr() if you use C style strings, and I'm sure that the STL library will have functions to search for substrings as well, either in the string library itself or in the algorithm library. It would also be instructive to write your own function to familiarize yourself with the workings of strings. Last, but not least, if you aren't familiar with the concept of strings at all, then this project is beyond your scope of programming at this point and you should set your sights a little lower for now---like learning about strings, working with files, etc.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: Search a txt file for words

 
0
  #6
Aug 16th, 2006
Show some effort. I don't think anyone here will give you code this way.
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Search a txt file for words

 
0
  #7
Aug 16th, 2006
Look into string methods, like .find(), .delete(), etc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC