Looking for examples for string related programs

This is a discussion on Looking for examples for string related programs within the C Programming forums, part of the General Programming Boards category; I am looking for some examples of source code relating to strings, specifically related in their operation on text files. ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2

    Looking for examples for string related programs

    I am looking for some examples of source code relating to strings, specifically related in their operation on text files. In reguards to this I am looking for a "net nanny" like program, that searches the text file and removes particular words from the file.

    If you have any ideas I'de love to hear from you.

    Koloth

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Bout the source code... just show what you got this far, you'll never learn anything by copy'n paste (dont flame on this one ).

    Anyway heres what i would do::no code, not even pseudo-code::
    but that gives you an idea of how i would work on this... so its prolly a messy way but it should work.

    I would just read in the file line per line with fgets.
    And you scan every line for a word then if the word isnt in that line you copy the whole line in a temporary file.But if the word IS in one of those lines you copy everything except for that word into the temporary file. Afterwards you copy everything from the temp file into the original one... (or you could work with the system functions and delete the original file, and then rename the temp file into the original, but i wouldnt do this coz if something goes wrong you can lose your temp and your original file)

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    913

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2

    Interesting

    Hmmm, the idea about the fgets is one I hadn't considered, as I have been playing around with the idea of reciving every character individually then storing the word in a string and having an array of pointers pointing to the entirerty of the sentance. Though admittedly that creates an totally redundant file structure, and is rather inefficient in large text files.

    Is you have some example code on how the fgets and scan's would work I'de love to see them,

    and don't worry, no flames here, just after ideas and some examples.

    Thanks.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    just check out the examples at cplusplus.com reference page. they have examples of all functions in all of the standard libraries.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I am so bored today

    Code:
    create an array of words to search for.
    for(each file to be searched)
         find file size
         alloc memory
         read whole file to alloced memory
         for(each element of word array)
               //search file with strstr
               if(strstr(sFile,sWord[i])!=NULL)//found match
                  process as per requirements
        free memory
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  2. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  3. Communication between programs?
    By johny145 in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2005, 10:14 PM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 04:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21