Click to See Complete Forum and Search --> : Txt file seach


redspider
December 26th, 2004, 03:08 AM
I have a text file with a list of names and a number under each name.
eg.
----------------------
John
1928
greg
19342
mark
235
----------------------
This list goes up to 500 lines.
How can i search for a name and get the number under that name and store it.
Useing api, Not iostream.
:)

Marc G
December 26th, 2004, 04:00 AM
Use CreateFile to open the file.
Use ReadFile to read the entire file into a memory buffer.
Use strtok to split the buffer on \r\n.
Use strcmp or stricmp to compare the string with the string you're searching for.

NoHero
December 26th, 2004, 05:48 AM
Dito. But something that can help to: Everyname starts with a non-numerical letter so you can use isdigit() to determinate if the first letter of a line is a digit or not. That makes the entire search engine a bit faster. Because you only check one character and not the entire string.

Marc G
December 26th, 2004, 08:22 AM
Dito. But something that can help to: Everyname starts with a non-numerical letter so you can use isdigit() to determinate if the first letter of a line is a digit or not. That makes the entire search engine a bit faster. Because you only check one character and not the entire string.
True; nice optimization :thumb:

NoHero
December 26th, 2004, 08:33 AM
True; nice optimization :thumb:

Just here to help :cool:

Marc G
December 26th, 2004, 12:42 PM
Just here to help :cool:
I would've rated your reply, but I'm not yet allowed to do so...

NoHero
December 26th, 2004, 12:50 PM
I would've rated your reply, but I'm not yet allowed to do so...

I also hate the


You must spread some Reputation around before giving it to Marc G again.


Message. It may cause users to give others a reputation - who probably don't deserve it - only because they aren't allowed to give the right one the reputation.

Marc G
December 26th, 2004, 02:42 PM
It may cause users to give others a reputation - who probably don't deserve it - only because they aren't allowed to give the right one the reputation.
True... but they did it to prevent two people from constantly voting for each other without reason ;)
Anyway, we are not here only for the votes ;) :wave:

NoHero
December 26th, 2004, 03:35 PM
True... but they did it to prevent two people from constantly voting for each other without reason ;)
Anyway, we are not here only for the votes ;) :wave:

Of course. It must have a benefit otherwise it would not be part of this software here :rolleyes: But I was too stupid to see.