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

R

RSBakshi

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 : (e-mail address removed)
 
B

broeni

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
 
D

David Resnick

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 : (e-mail address removed)

No thanks, I prefer to post :p

-David
 
C

Christopher Benson-Manica

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 : (e-mail address removed)

Post here, read here.
 
O

osmium

Christopher Benson-Manica said:
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.
 
K

Keith Thompson

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top