1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
/*****************************************
Phone Number List
******************************************/
# include <iostream> // i/o stream header
# include <cstring> // header file needed to use strstr function
using namespace std;
/******************
Function Main
******************/
int main ()
{
const int num = 11; // num holds 11 contacts
const int length = 100; // Maximum allowable charactersfor each line is 100
// Array contacts[][] holds 11 contacts with phone numbers
char contacts[num][length] = { "Becky Warren, 555-1223",
"Joe Looney, 555-0097",
"Geri Palmer, 555-8787",
"Lynn Presnell, 555-1212",
"Holly Gaddis, 555-8878",
"Sam Wiggins, 555-0998",
"Bob Kain, 555-8712",
"Tim Haynes, 555-7676",
"Warren Gaddis, 555-9037",
"Jean James, 555-4949",
"Ron Palmer, 555-2783"};
char search[length]; //Array search[] holds user's input
//and searches inside the array contacts[][]
char *IdContact = NULL; // IdContact points to the user's query inside array contacts[][]
int index; // loop counter
//Prompts user to search for contacts
cout << "To search for your contact's number please enter a name or partial name of the person.\n";
cin.getline(search, length); //user's input
//Searches array for matching substring
for (index = 0; index < num; index++)
{
IdContact = strstr(contacts[index], search);
if (IdContact != NULL)
{
cout << contacts[index]; //prints all possible contacts with in the string
}
}
//if no matches are found, display error message;
if (IdContact == NULL)
cout << "Sorry, No matches were found!";
return 0;
}
|