This program is supposed to have an array of 10 string objects that hold people's names and phone numbers. It asks the user to enter a name or partial name to search for in the array, and any entries in the array that match the string entered should be displayed. I'm having problems executing the code.
#include "stdafx.h"
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
const int size = 50;
char name[50];
int count;
char list[] = {"Becky Warren, 555-1223",
"Joe Looney, 555-0097",
"Geri Palmer, 555-8787",
"Lynn Presnell, 555-8878",
"Holly Gaddis, 555-8878",
"Sam Wiggins, 555-0998",
"Bob Kain, 555-8712",
"Tim Haynes, 555-7676",
"Warren Gaddis, 555-9037",
"Jean James, 555-4939",
"Ron Palmer, 555-2783"};
cout << "Enter a name or partial name: " << endl;
cin.getline(name, size);
cin.ignore();
for(count = 0; count < 10 ; count++){
if(strstr(list[count], name)){
cout << list[count];
}
}
cin.get();
return 0;
}
strstr
is case sensitive, so "Becky" is not equal to "becky". – Joachim Pileborg Dec 15 '11 at 8:29