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 3916
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.
sicarie 4,677
Recognized Expert Moderator Specialist
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 possible, "Hi, thanks for
stopping by Demaux Motors. Before we get started, can I get your phone
number, please? Oh, HI Joe, you still live on Gingerbread lane..?" etc etc
etc. Filling out the form is easy - sql query, javascript, blah blah...
|
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
format of any country. I would like to be able to automatically display the
information in the format of their country based on the information gathered
from the Country field in the database.
Is there any white paper, or book or site that has...
|
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 like T9 on
the mobile phones)
According to the http://www.yorku.ca/mack/uist01.html
dictionary-based disambiguation is coming in the mind.
With dictionary-based disambiguation, each key is pressed only once.
For example, to enter the, the...
|
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 code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber, homeNumber, mobile, ipphone, facsimileTelephoneNumber...the properties are...
|
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 code that seems to work. It queries Active Directory for a phone list and correctly retrieves the names (cn) from the OU. Though I have asked for properties like telephoneNumber, homeNumber, mobile, ipphone, facsimileTelephoneNumber...the properties are...
| |
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 of the current Windows
user.
I guess the name can be retrieved from the environment -- After I
click the Start button of Windows, my name is on the very first line
of the popup menu. So, this information is provided by the Windows
|
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 "special" because they are easily translated into words. You've been asked to create a list of phone numbers that are directly mappable to words by searching a dictionary for every 7 or 10 letter word that maps on to the phone lettering scheme:
...
|
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 named "l" on the next page.
This variable is the Last name reference to search a name on a corporate directory.
here are the 2 pages of code
first it's a keyboard like html clickable picture it refere coordinates to zone from the TouchArea tag...
|
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |