473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Phone Number List (NEED HELP WITH SEARCH)

I need this program to find all occurences of a name and display them.
If I enter Palmer, I need it to display all the Palmers in the list.
Can anyone help me Please. Thank You!!

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     const int NUMBERS = 11, S_LENGTH = 50;
  8.     char list[11] [S_LENGTH] = {"Becky Warren 678-1223",
  9.                                 "Joe Looney, 586-0097",
  10.                                 "Geri Palmer, 223-8787",
  11.                                 "Lynn Presnell, 887-1212",
  12.                                 "Holly Gaddis, 223-8878",
  13.                                 "Sam Wiggins, 486-0998",
  14.                                 "Bob Kain, 586-8712",
  15.                                 "Tim Haynes, 586-7676",
  16.                                 "Warren Gaddis, 223-9037",
  17.                                 "Jean James, 678-4939",
  18.                                 "Ron Palmer, 486-2783"}; 
  19.  
  20.     char lookUp[S_LENGTH], *strPtr = NULL;
  21.     int count;
  22.  
  23.     cout<< "\tPhone Number List\n\n";
  24.     cout<< "Enter a name or partial name to search for: \n";
  25.     cin.getline(lookUp, S_LENGTH);
  26.  
  27.     for  (count=0; count < NUMBERS; count++)
  28.     {
  29.         strPtr = strstr(list[count],lookUp);
  30.  
  31.         if (strPtr !=NULL)  
  32.          break;
  33.     }       
  34.  
  35.     if (strPtr == NULL)
  36.        cout<< "No matching name was found.\n";    
  37.     else
  38.        cout<< list[count]<<endl;
  39.  
  40.  
  41.  
  42.     system("PAUSE");
  43.     return 0;
  44. }
Jul 19 '07 #1
4 3911
scruggsy
147 100+
That code will find the first Palmer in the list, but since you break out of your loop as soon as the first match is found, you won't ever find more than one match.
So you'll want to print out each match as it is found, and continue looping until there are no more names to check against.

Hope this helps.
Jul 19 '07 #2
archonmagnus
113 100+
If you've already #included string, why not use strings (and the accompanying members of the string class) rather than character arrays?
Jul 19 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
Yes, and also why not use a vector<string>?

Your lookup code is a duplication of STL code.
Jul 22 '07 #4
sicarie
4,677 Expert Mod 4TB
mustang07-

Please check your PM's (located at the top right of the page).

Thanks,

sicarie
Jul 23 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William Morris | last post by:
Our application tracks contact information. One of our clients, a car dealership, has asked about being able to enter a lastname and phone number and getting as much of the main form filled out as...
5
by: Kamaluokeakua | last post by:
I have to write an application that deals with clients in multiple countries. The addresses, phone numbers, country id and currency information has to be stored into a database that allows for the...
10
by: Petr Jakeš | last post by:
I have a standard 12-key mobile phone keypad connected to my Linux machine as a I2C peripheral. I would like to write a code which allows the text entry to the computer using this keypad (something...
1
by: htperth | last post by:
Hi all, Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app...
1
by: htperth | last post by:
Hi all, Note that I'm new to LDAP and Active Directory and am writing an application that retrieves a simple phone list for all the users in our domain. So far I have the following console app...
9
by: Alex | last post by:
Get the Name and Phone Number of the Current Windows User in a .NET Application I am writing a simple .NET (C#) application. It needs to "automatic" get the Name (last, first) and phone number...
5
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are...
0
terryble
by: terryble | last post by:
hy, We are deploying IPPhone cisco(R) On this phone proprietary code exist with XML too. After code modification, a can't find the final step for this service to work. I need to post the variable...
0
by: hennas | last post by:
Basically i want to design a membership Name and Telephone List form using the following command buttons. Edit Add New; Update; Delete; Cancel; Save; Clear, and Exit
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.