How to filter words from a file

This is a discussion on How to filter words from a file within the C Programming forums, part of the General Programming Boards category; I've been trying to make a swear filter for text documents where the program takes in strings at the command ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    5

    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

    filter.txt:
    i love you, you hate me
    from me

    Output:
    love hate
    from

    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
    Posts
    236
    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, 01:44 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11: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

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