471,584 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,584 software developers and data experts.

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

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 : rs******@gmail.com

Jan 12 '06 #1
5 2041
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 '06 #2
RS******@gmail.com 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 : rs******@gmail.com


No thanks, I prefer to post :p

-David

Jan 12 '06 #3
RS******@gmail.com 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 : rs******@gmail.com


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.
Jan 12 '06 #4
"Christopher Benson-Manica" writes:
RS******@gmail.com 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.
Jan 12 '06 #5
RS******@gmail.com 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) ks***@mib.org <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.
Jan 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by mike | last post: by
3 posts views Thread by George B | last post: by
2 posts views Thread by Pablo | last post: by
64 posts views Thread by Morgan Cheng | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.