Thread: How to filter words from a file

  1. #1
    Registered User
    Join Date
    Jan 2003

    How to filter words from a file

    I've been trying to make a swear filter for text documents where the program takes in strings at the command line and the text file but I am having problems figuring out how to do it.

    Example application: (random words instead of swears)
    filter.out i you me < filter.txt

    i love you, you hate me
    from me

    love hate

    I understand how to print to files using fprintf and how to read and print out a file on its own. But how do I read it, remove the words I want and continue printing the file? I cant seem to figure it out. I'm using strncmp to try and compare, but once I compare them, I dont know how to replace it in the file.

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    You want to output all of the text to a new file (probably word by word in a loop), but skip the text that you don't want kept. Then delete the original file and rename your new one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM