i'm trying to search an array of ten strings so that when the user enters the name to search for in the array, it will return all instances of that name. this is the code i have written that returns only ONE hit.
#include <iostream.h>
#include<string.h>
void main(void)
{
char NamePhone[11][30] = {"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[30], *StrPtr = NULL;
cout << "\tPhone Number List\n\n";
cout << "Please enter the name whose phone number you wish to search for: ";
cin.getline(LookUp, 30);
for (int Index = 0; Index < 11; Index++)
{
StrPtr = strstr(NamePhone[Index], LookUp);
if (StrPtr != NULL)
break;
}
if (StrPtr == NULL)
cout << "No matching name found.\n";
else
cout << NamePhone[Index] << endl;
}
can anybody help me modify this code so it returns multiple instances of the name being searched for?
for example if i types the name Palmer, it should come out like Geri Palmer, 223-8787
Ron Palmer, 486-2783
hope this doesn't confuse anybody, thanks!
-=metpage=-
[email protected]