Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. // Constants for array lengths
  9. const int numNames = 10;
  10. const int LENGTH = 30;
  11.  
  12. // Array of phone numbers
  13. char phoneNumbers[numNames][LENGTH] = { "Renee Javens, 678-1223", "Joe Looney, 586-0097",
  14. "Geri Palmer, 223-8787", "Lynn Presnell, 887-1212",
  15. "Bill Wolfe, 223-8878", "Sam Wiggins, 486-0998",
  16. "Bob Kain, 586-8712", "Tim Haynes, 586-7676",
  17. "John Johnson, 223-9037", "Jean James, 678-4939" };
  18.  
  19. char lookup[LENGTH]; // To hold user's input
  20. char *strPtr = nullptr; // To point to the found name
  21. int index; // Loop counter
  22.  
  23. // Prompt the user for a name or partial name
  24. cout << "\tPhone Number List\n\n";
  25. cout << "Enter a name or a partial name to search for: ";
  26. cin.getline(lookup, LENGTH);
  27.  
  28. // Search the array for a matching substring
  29. for (index = 0; index <= numNames; index++)
  30. {
  31. strPtr = strstr(phoneNumbers[index], lookup);
  32. if (strPtr != nullptr)
  33. break;
  34. }
  35.  
  36. // If a matching substring was found, display the product info
  37. if (strPtr != nullptr)
  38. cout << phoneNumbers[index] << endl;
  39. else
  40. cout << "No matching name was found.\n";
  41.  
  42. system("pause");
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement