Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Search Text File For A Word Using C++


  • Please log in to reply
2 replies to this topic

#1 ardynne

ardynne

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:05:46 AM

Posted 10 September 2006 - 07:01 AM

Hi, I am trying to write a c++ code that searches a text file for a word. If you are familiar with VB, this is what I am after:


Open textFile For Input As #1
i1=1
Do


Line Input #1, dataline
dataline = lcase$(dataline)
i1 = InStr(1, dataline, "word")
If i1 = 0 Then i1 = 1

Loop Until Mid(dataline, i1, 4) = "word" Or EOF(1)


i.e.: Open file for input (read), and search each line for the word
Thanks a lot for your help guys,
A

Edited by ardynne, 10 September 2006 - 07:02 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:11:46 PM

Posted 10 September 2006 - 10:40 AM

Here is code for reading a file into an array of lines:
http://www.differentpla.net/node/117

Then all one needs to do is search the given line for the string. Java has a method called 'contains', I am guessing that c++ probably has the same thing.

#3 ardynne

ardynne
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:05:46 AM

Posted 12 September 2006 - 02:51 PM

Thanks for the help, although I have to admit that it will take me a while to get my mind around this, specially when having to deal with pointers and other such C++ delicatessen! but never the less I'll try.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users