The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
compare numbers in a textfile
Discuss compare numbers in a textfile in the C Programming forum on Dev Shed. compare numbers in a textfile C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 15th, 2004, 06:03 AM
|
|
Registered User
|
|
Join Date: Jun 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
compare numbers in a textfile
I have at textfile called about.txt where every line har 3 fields, it is built like this : name:sequensnumber:weeknumber
with this information :
nils:345:12
donald:234:14
isac:256:49
nolan:345:10
I want to compare field number 2(sequensnumber) with eachother in this file and print the fields if there are two that are alike.
eks. nils:345:12 has the same number nolan:345:10
in this file there is colons ( : ) between every information.
please help me.
|

June 15th, 2004, 07:18 AM
|
 |
Lord of Dorkness
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
I'd read each line, tokenize on the colon, store the tokens in an array of structs, sort on the second member, iterate through, and print duplicates.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.
|

June 15th, 2004, 09:28 AM
|
|
popndekl™®©
|
|
Join Date: Mar 2004
Location: Slovenia
Posts: 196
Time spent in forums: 5 h 15 m 55 sec
Reputation Power: 10
|
|
|
it also work if you do scanf("%d:%d:%d", ...) - fscanf or sscanf, you choose. i don't know if this is "legal", but it works for me - i sscanf a date in format dd.mm.yyyy that way.
|

June 15th, 2004, 09:33 AM
|
 |
Lord of Dorkness
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
I believe that would be classified as "reading the line and tokenizing on the colon."
|

June 15th, 2004, 09:45 AM
|
 |
I'm Baaaaaaack!
|
|
Join Date: Jul 2003
Location: Maryland
|
|
|
I can see your icon as looking like little ginger bread cookies now, maybe because I am hungry. Yesterday it looked like an abacus to me until I saw infamous' comment, but they look delicious today.
Did you bring enough for everyone?
|

June 15th, 2004, 01:31 PM
|
|
popndekl™®©
|
|
Join Date: Mar 2004
Location: Slovenia
Posts: 196
Time spent in forums: 5 h 15 m 55 sec
Reputation Power: 10
|
|
|
???
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|