|
-
January 17th, 2010, 09:25 AM
#1
Searching a string for information
Hey guys, im quite new to c++. i am doing a project in which i would have to extract certain information of a database which i have saved in a text file. the database looks something like this :
Database
John32451^23.21 >tyyhg>tdsrte^>1.24
Mark55342^ 335.11 >tsthh
What i am trying to do is search each row based on a specific id and then extract the information next to it. For example, if i were to select John in the menu, the output will be like this.
OUTPUT
John 23.21 1.24
I am not very sure how could i do this and the method to use. Could i get some guidance? To get the correct line will be easy as we just have to search for the name to get the line. But , how about the other two information? I was thinking of using the characters before it which is "32451^" and then reading the info. but how do i get it to stop at the information i want and not continue displaying the information after that which is ";gt;t"
-
January 17th, 2010, 12:12 PM
#2
Re: Searching a string for information
You haven't given much to go on. I'd probably read the file, search each string for the first numeric character and use a map to map the name to that person's record. That of course, assumes each name is unique.
From there you could use strtok, or just a manual search of the characters in the record to extract the info you want. You didn't specify how to determine what you want and I have no idea where ";gt;t" came from, so I can't really give you more than that.
-
January 18th, 2010, 12:07 AM
#3
Re: Searching a string for information
Sorry i think i missed out some info when i pasted my database. The info in the database is displayed like this
John32451^23.21 >tyyhg>tdsrte^>1.24
the information which i want retrieved would be the 23.21 and 1.24.
the problem i am having is how do i get the prog to read this two numbers and display it.
I guess the best way would be to do a search on the unique id which will be "John32451^" as the value i want is next to it. but from there, how do i get the prog to read the value till it ends with a ">"?
Hope that explains more GCDEF
-
January 18th, 2010, 08:30 AM
#4
Re: Searching a string for information
It depends on the format of your records. One entry is hardly enough to ascertain the format. Are the fields fixed width? Is the ">" character a delimiter of some sort? Are records separated by a CR and/or LF? Do you need numeric values for the number fields? Functions like strtok, strchr and others like atoi or atof from the standard C libraries might be effective, but we still need more info.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|