Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include <cstring>
- using namespace std;
- int main()
- {
- // Constants for array lengths
- const int numNames = 10;
- const int LENGTH = 30;
- // Array of phone numbers
- char phoneNumbers[numNames][LENGTH] = { "Renee Javens, 678-1223", "Joe Looney, 586-0097",
- "Geri Palmer, 223-8787", "Lynn Presnell, 887-1212",
- "Bill Wolfe, 223-8878", "Sam Wiggins, 486-0998",
- "Bob Kain, 586-8712", "Tim Haynes, 586-7676",
- "John Johnson, 223-9037", "Jean James, 678-4939" };
- char lookup[LENGTH]; // To hold user's input
- char *strPtr = nullptr; // To point to the found name
- int index; // Loop counter
- // Prompt the user for a name or partial name
- cout << "\tPhone Number List\n\n";
- cout << "Enter a name or a partial name to search for: ";
- cin.getline(lookup, LENGTH);
- // Search the array for a matching substring
- for (index = 0; index <= numNames; index++)
- {
- strPtr = strstr(phoneNumbers[index], lookup);
- if (strPtr != nullptr)
- break;
- }
- // If a matching substring was found, display the product info
- if (strPtr != nullptr)
- cout << phoneNumbers[index] << endl;
- else
- cout << "No matching name was found.\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement