| | |
Kindly help me...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
The simplest, but slowest, way is to do a linear search -- start from the beginning of the file, read each record until you get the one you want. For files written in text mode there isn't much more that can be done to speed up the searches.
A more complicated method is to create an index file that contains key field values and the index value into the data file.
A more complicated method is to create an index file that contains key field values and the index value into the data file.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
If you want to find a name and display the telephone number you have to loop through each person in the address book and then use the strcmp function which takes two char pointers as parameters and returns 0 if they match.
It would look something similar to this:
The only problem with this is that if you want to search for part of a name, the code above wont work. So in order for the program to return "John Smith´s" number by just typing the name "John", you need a seperate function that checks to see whether "John Smith" contains the word "John".
For this try looking up the strstr function.
Hope this helps.
It would look something similar to this:
C++ Syntax (Toggle Plain Text)
char *nameToFind = "John"; for (int i = 0; i < peopleCount; ++i) { if (strcmp(names[i], nameToFind) == 0) { std::cout << phoneNo[i]; } }
The only problem with this is that if you want to search for part of a name, the code above wont work. So in order for the program to return "John Smith´s" number by just typing the name "John", you need a seperate function that checks to see whether "John Smith" contains the word "John".
For this try looking up the strstr function.
Hope this helps.
Last edited by William Hemsworth; Jul 31st, 2008 at 4:47 pm.
I need pageviews! most fun profile ever :)
![]() |
Similar Threads
- Kindly tell the flaw in the code? (C++)
- how to write I.N.I database in my path....kindly see (Visual Basic 4 / 5 / 6)
- Internet Explorer not working. (Web Browsers)
- Need Affiliates (interested Personnels Kindly Apply) (Tech / IT Consultant Job Offers)
- kindly solve this problem (Windows NT / 2000 / XP)
- PLease kindly help me, Please!! (Windows Servers and IIS)
- kindly have a look at my pages (Website Reviews)
- problem with loop back (Networking Hardware Configuration)
- Has Acacia threatened to sue you yet? (Geeks' Lounge)
Other Threads in the C++ Forum
- Previous Thread: Containers Perfomance testing - memory error
- Next Thread: Beggining question for c++
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






