473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2114
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: mike | last post by:
I have created a side application in VB.NET which reads rows from a DB and builds an email message. when i have a long string the the mailmessage.body or the mailmessage, it puts in an...
3
by: George B | last post by:
When I redirect standard output, I would like to duplicate a few lines of this output to the console. If I add duplicates of the desired source statements, changing cout to cerr, it works fine,...
2
by: Pablo | last post by:
Hello, there, I have a table tblData which has pharmacy data. The table has following fields: ClaimNum, LineNum... The ClaimNum has claim number which is 12 characters. LineNum is NULL. The...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
6
by: Sharon | last post by:
Usually it is common to write the class member function in the class H file, but some people like to write the function body in the C++ file. Can anybody tell me what are the cases where inline...
2
by: Kevin Blount | last post by:
I've been trying all morning to find a way that will let me add new lines to a string that will form the body of an email. The problem is that some lines are not appearing as new line, but rather...
1
by: JRWarring | last post by:
I have a VB application with about 75 installations that uses the Crystal Control (Version 7.0) to print Crystal RPTs. On about 7 of these installations the clients are getting duplicate lines...
4
by: sadieslc | last post by:
I'm working on a PHP script, and the info from the form shows up in the headers of the email that I receive, but it doesn't show up in the body of the email. Can you please help me figure out what...
1
by: VinArt | last post by:
MS Acc 2003, XP Thank you in advance for any help. I have tables called "Makeup" and "Lines". Each makeup can have multiple lines. Goal is to create a new "makeup" with identical "lines"...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.