Click here to Skip to main content
15,918,889 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: String Search Pin
kanduripavan3-Apr-07 23:02
kanduripavan3-Apr-07 23:02 
GeneralRe: String Search Pin
yaminisridaran3-Apr-07 23:06
yaminisridaran3-Apr-07 23:06 
GeneralRe: String Search Pin
kanduripavan4-Apr-07 1:12
kanduripavan4-Apr-07 1:12 
GeneralRe: String Search Pin
yaminisridaran6-Apr-07 18:22
yaminisridaran6-Apr-07 18:22 
Questionhelp [modified] Pin
tanchinchee1-Apr-07 19:45
tanchinchee1-Apr-07 19:45 
AnswerRe: help Pin
Cedric Moonen1-Apr-07 20:35
Cedric Moonen1-Apr-07 20:35 
GeneralRe: help Pin
tanchinchee3-Apr-07 3:10
tanchinchee3-Apr-07 3:10 
GeneralRe: help Pin
Cedric Moonen3-Apr-07 7:46
Cedric Moonen3-Apr-07 7:46 
Well, the problem is in fact not a single problem: you are asking quite different things so let's decompose everything.

In general, the best way to deal with these kind of situations (meaning, you have a file containing information that you need to access 'often) is to read the file once and store everything in memory.

1) How to store the data in memory ?
It looks like you have an undefined amount of data (names in your case) to read from the file. So we will need a kind of array to store this information. Two options: either you use the standard C++ arrays (using new[] operator) or you use a container class from the STL. I suggest the container from the STL: it is much more powerfull and flexible (and does all the memory management for you) but if you are a beginner, it might a little bit tricky at the begining (hopefully, there are quite a lot of tutorials). I recommand using the std::list in your case. Here[^] is a tutorial for example, but using google you can find a lot. Honnestly, it is worth the time to learn how to use it, you'll see in the future that it is very very helpfull.

What you could do is to have a structure for each entry of your file (that contains all the info about one person). Then use a std::list of these structures.

2) How to read data from the file ?
Now that you know how to store data in memory (more or less at least), you will need to read your data from the file. Here, it is difficult to help because I have absolutely no idea of how the data is formated in your file. If you could post a short example of the file it would be helpfull.
But again, you read each entrey one by one and for each of them, you fill a structure (the one explained in point 1) and you add it in your list. You continue until you reach the end of your file (EOF).

3) How to retrieve data from your list ?
That's not very difficult once you are familiar with the std::list. You can simply loop through your list until you find the information that you need.

Also, what you could do is using a std::map instead. It store in fact the data with a certain key so that you can easily find it afterward (with only the key).

Hope that helps, it is quite a broad subject so it is too long to enter in the details. You'll need to work a little bit by yourself.


Cédric Moonen
Software developer

Charting control [v1.1]

GeneralRe: help Pin
tanchinchee3-Apr-07 22:17
tanchinchee3-Apr-07 22:17 
GeneralRe: help Pin
Cedric Moonen4-Apr-07 1:04
Cedric Moonen4-Apr-07 1:04 
GeneralRe: help Pin
tanchinchee4-Apr-07 22:01
tanchinchee4-Apr-07 22:01 
GeneralRe: help Pin
Cedric Moonen5-Apr-07 0:50
Cedric Moonen5-Apr-07 0:50 
Questionno response [modified] - why Pin
deeps_cute1-Apr-07 19:10
deeps_cute1-Apr-07 19:10 
QuestionRe: no response Pin
Hamid_RT1-Apr-07 19:51
Hamid_RT1-Apr-07 19:51 
AnswerRe: no response Pin
deeps_cute1-Apr-07 19:54
deeps_cute1-Apr-07 19:54 
GeneralRe: no response Pin
Hamid_RT1-Apr-07 20:14
Hamid_RT1-Apr-07 20:14 
GeneralRe: no response Pin
deeps_cute1-Apr-07 20:25
deeps_cute1-Apr-07 20:25 
GeneralRe: no response Pin
Hamid_RT2-Apr-07 1:01
Hamid_RT2-Apr-07 1:01 
GeneralRe: no response Pin
prathuraj2-Apr-07 17:28
prathuraj2-Apr-07 17:28 
GeneralRe: no response Pin
Hamid_RT6-Apr-07 4:15
Hamid_RT6-Apr-07 4:15 
GeneralRe: no response Pin
ThatsAlok2-Apr-07 1:35
ThatsAlok2-Apr-07 1:35 
AnswerRe: no response [modified] - why Pin
cp98761-Apr-07 20:05
cp98761-Apr-07 20:05 
QuestionMain frame and Child frame Pin
Kiethnt1-Apr-07 17:22
Kiethnt1-Apr-07 17:22 
AnswerRe: Main frame and Child frame Pin
CPallini1-Apr-07 21:01
mveCPallini1-Apr-07 21:01 
AnswerRe: Main frame and Child frame Pin
Kiethnt1-Apr-07 21:12
Kiethnt1-Apr-07 21:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.