Thread: search a file for a string?

  1. #1
    Unregistered
    Guest

    Question search a file for a string?

    I have read the entire contents of my HD into a file called log1.log. I want to search that file to see if the word winzip appears anywhere within the file? what would the best way to go about this be? currently I am reading in each line of the file like this:
    logFile.open("log1.log");
    logFile.getline(line,255,'\n');
    where line is a character array. I heard that maybe the strstr command would help me, but I got kind of stuck using it. Can someone please tell me if I am on the right track. Or if someone knows of a better way to go about this please let me know. Also, instead of reading all the resluts of the dir command into a file(which takes a while to search) can I just scan the HD for winzip32.exe? thanks for the help.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    strstr() will return a pointer to a specified substring, so you'd have to do something like -

    char* pos = strstr(buffer,"winzip32.exe");

    for every line you read, until pos doesn't return NULL. Alternatively you could use FindFirstFile() and FindNextFile() to recursively search your drive(s) for the exe. Or use the registry functions (RegOpenKeyEx() and RegQueryInfoKey()) to open the relevent key and obtain the path where it's been installed.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM