473,624 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2123
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.programmin g 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)cybers pace.org | don't, I need to know. Flames welcome.
Jan 12 '06 #4
"Christophe r 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.programmin g.
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.programmin g;
if you've having problems implementing the algorithm in C, you're in
the right place.)

--
Keith Thompson (The_Other_Keit h) 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
3461
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 "!<linefeed><space>" at about every 980th space. I have confirmed that these characters are not in the string or the message body before the email is sent. Has anyone seen this or have any thoughts? Thanks
3
2183
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, but I end up with duplicated lines when the program is executed without redirection. Is there a way to test cout to tell whether its output is being redirected? Like, cout << "This information is very important" << endl; if (cout_is_redirected)...
2
1925
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 table looks like this ClaimNum LineNum abcde1234561 abcde1234561
64
3363
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 "refactor-ed" to be
6
2103
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 function should not be written in the C++ file? Or what are the disadvantages of inline function body in a C++ file? -- Regards Sharon G.
2
2122
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 are being appended to existing lines. Here's my (cut down) code: string sbInstructions = string.Empty; char endOfLine = '\n'; sbInstructions += "" + endOfLine; sbInstructions += "DupCheck=email" + endOfLine;
1
1827
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 (usually on the last page or a single page report). 1) Using the same data (and reports) we cannot create this problem on any workstations execpt the 7 workstations that have the problem. 2) We do not think it a data problem, since we can clearly see in...
4
1846
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 I'm doing wrong? Here is the script: <? function send_mail($emailaddress, $fromaddress, $emailsubject, $body) { $eol="\r\n"; $mime_boundary=md5(time()); # Common Headers
1
2224
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" except with a new makeup id. I created a form Makeup Copy with Line Subform. In the main form there is ID (key field), Comments, Customer, Description plus an unbound field "NewMakeup". Each line of the subform has the fields "Makeup (primary...
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.