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!! -
#include <iostream>
-
#include <string>
-
using namespace std;
-
-
int main()
-
{
-
const int NUMBERS = 11, S_LENGTH = 50;
-
char list[11] [S_LENGTH] = {"Becky Warren 678-1223",
-
"Joe Looney, 586-0097",
-
"Geri Palmer, 223-8787",
-
"Lynn Presnell, 887-1212",
-
"Holly Gaddis, 223-8878",
-
"Sam Wiggins, 486-0998",
-
"Bob Kain, 586-8712",
-
"Tim Haynes, 586-7676",
-
"Warren Gaddis, 223-9037",
-
"Jean James, 678-4939",
-
"Ron Palmer, 486-2783"};
-
-
char lookUp[S_LENGTH], *strPtr = NULL;
-
int count;
-
-
cout<< "\tPhone Number List\n\n";
-
cout<< "Enter a name or partial name to search for: \n";
-
cin.getline(lookUp, S_LENGTH);
-
-
for (count=0; count < NUMBERS; count++)
-
{
-
strPtr = strstr(list[count],lookUp);
-
-
if (strPtr !=NULL)
-
break;
-
}
-
-
if (strPtr == NULL)
-
cout<< "No matching name was found.\n";
-
else
-
cout<< list[count]<<endl;
-
-
-
-
system("PAUSE");
-
return 0;
-
}
4 3911
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.
If you've already #included string, why not use strings (and the accompanying members of the string class) rather than character arrays?
Yes, and also why not use a vector<string>?
Your lookup code is a duplication of STL code.
mustang07-
Please check your PM's (located at the top right of the page).
Thanks,
sicarie
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
| |