Thread: how to remove duplicate words from a text file through c code

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    1

    how to remove duplicate words from a text file through c code

    hey... i want to remove duplicate words from a text file.
    My file contains one word per line.
    So what i need to do is to read line by line to compare the words.
    I used gets function t retieve the words and strcmp to compare them but they are not working. I dont why... So please can anyone help me with this.

    My fIle looks like...

    reason
    ressen
    leesen
    lesser
    reason
    lesser

    And i want to remove the duplicate words i.e. reason ,lesser

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    One approach is to store the words in an array, sort them, then make a single pass over the array to only write unique words to file.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    You could start by showing us the code that you attempted. Please read our homework policy. I would like to add that someone, hint: not me, has given you a solution.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. remove duplicate words from linked list
    By rocketman03 in forum C Programming
    Replies: 8
    Last Post: 11-22-2008, 07:47 PM
  2. How to check duplicate line in text file?
    By ooosawaddee3 in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2002, 06:35 PM
  3. Remove Duplicate Functions
    By dhartwig1023 in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2002, 01:21 PM
  4. How do I remove duplicate entries in an array?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 06-18-2002, 09:49 AM
  5. How to erase duplicate lines in a text file?
    By miketv in forum C Programming
    Replies: 0
    Last Post: 02-25-2002, 11:18 PM