473,837 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Phone Number List (NEED HELP WITH SEARCH)

2 New Member
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 3927
scruggsy
147 New Member
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 New Member
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 Recognized Expert Moderator Expert
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 Recognized Expert Moderator Specialist
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
2254
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...
5
3532
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...
10
6477
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...
1
2855
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...
1
3985
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...
9
3006
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
5
3305
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: ...
0
3212
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 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...
0
1374
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
9843
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, 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...
0
9682
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,...
0
10875
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10623
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9401
agi2029
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...
1
7806
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7001
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();...
0
5669
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4474
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 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.