Can any body tell me how to find duplicate lines in C

Discussion in 'C Programming' started by RSBakshi@gmail.com, Jan 12, 2006.

  1. Guest

    Can any body tell me how to find duplicate lines in C

    i have tried to find using Binary tree and Text files but not suceeded
    ..

    It works for Word but not for lines

    please help me

    you can write suggetion to my email :
    , Jan 12, 2006
    #1
    1. Advertising

  2. Guest

    Put the lines in an array,
    sort the array by a) length of line, b) the line itself
    iterate the array checking for duplicates.

    Regards, Stephan
    , Jan 12, 2006
    #2
    1. Advertising

  3. wrote:
    > Can any body tell me how to find duplicate lines in C
    >
    > i have tried to find using Binary tree and Text files but not suceeded
    > .
    >
    > It works for Word but not for lines
    >
    > please help me
    >


    Your question isn't really a "C" question, but more an algorithm one.
    comp.programming might be a better place to ask it.

    Assuming you can slurp the whole file into an array (i.e. assuming
    you don't need to work on really big files, etc), you could use
    the following simple approach.

    1) slurp file into array (look at fgets, or cbfalconer's ggets code)
    2) sort the array (look at quicksort)
    3) iterate through the array, comparing each line to the next (look at
    strcmp)

    I expect is a good enough approach. Write some code and come
    back with it if you have problems.

    > you can write suggetion to my email :


    No thanks, I prefer to post :p

    -David
    David Resnick, Jan 12, 2006
    #3
  4. wrote:

    > i have tried to find using Binary tree and Text files but not suceeded


    How sad. Are you sure you didn't simply make a mistake in your code?

    > please help me


    http://www.ungerhu.com/jxh/clc.welcome.txt
    http://c-faq.com
    http://benpfaff.org/writings/clc/off-topic.html

    When you figure out what algorithm you want to use and have an attempt
    at implenting it in C to post here, come back. Until then...

    > you can write suggetion to my email :


    Post here, read here.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Jan 12, 2006
    #4
  5. osmium Guest

    "Christopher Benson-Manica" writes:

    > wrote:
    >
    >> i have tried to find using Binary tree and Text files but not suceeded

    >
    > How sad. Are you sure you didn't simply make a mistake in your code?


    I doubt that there are any real problems in doing this using a tree; it may
    not be the best way but it is surely *a* way. Or did you mean you just gave
    up and stopped working on it? BTW, the proper forum for this question is
    comp.programming.
    osmium, Jan 12, 2006
    #5
  6. writes:
    > Can any body tell me how to find duplicate lines in C
    >
    > i have tried to find using Binary tree and Text files but not suceeded
    > .
    >
    > It works for Word but not for lines


    The first thing you should do is figure out *why* it works for words
    but not for lines. The code that checks for duplicates should just be
    operating on strings; it shouldn't matter whether the strings are
    words or lines.

    Show us some code, and maybe we can help you figure out what the
    problem is.

    (If you're having problems with the algorithm, try comp.programming;
    if you've having problems implementing the algorithm in C, you're in
    the right place.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Jan 12, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mit
    Replies:
    0
    Views:
    399
  2. yogesh
    Replies:
    1
    Views:
    350
    Victor Bazarov
    Mar 14, 2007
  3. Mike A
    Replies:
    17
    Views:
    244
    Dr John Stockton
    Nov 19, 2003
  4. PerlFAQ Server
    Replies:
    0
    Views:
    154
    PerlFAQ Server
    Jan 14, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    140
    PerlFAQ Server
    Apr 19, 2011
Loading...

Share This Page