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!!
[code=cpp]
#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(loo kUp, 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;
}[/code]
If I enter Palmer, I need it to display all the Palmers in the list.
Can anyone help me Please. Thank You!!
[code=cpp]
#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(loo kUp, 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;
}[/code]
Comment