Iam suppose to make a program that creates an employee database of names, addresses, and phone numbers. the user to search by name for an employee in the database. if the name is not found output a message to that effect.
so far I have this but its giving me problems when I run the program. An screen pops up and says that there was a problem with the cmd.exe
then again in the program I know Iam missing something but what is it????/
#include <stdio.h>
struct database
{
char Name[36];
char Address[46];
char Phone[15];
};
int compare_strings (char s1[], char s2[])
{
int i=0, answer;
while ( s1[i] == s2[i] && s1[i] != '\0'&& s2[i] != '\0') ++i;
if ( s1[i] < s2[i])
answer = -1;
else if ( s1[i] == s2[i])
answer = 0;
else
answer = 1;
return (answer);
}
int lookup (struct database employee[], char search[],int entries)
{
int low =0;
int high = entries -1;
int mid, result;
int compare_strings (char s1[], char s2[]);
while (low <= high)
{
mid = (low + high) / 2;
result = compare_strings (employee[mid].Name, search);
if ( result == -1)
low = mid +1;
else if (result == 1)
high = mid - 1;
else
return (mid);
}
}
main()
{
struct database employee [100] =
{ {"Lisa ", "4300 sloping oak" },
{"Fernando", "2300 clearmeot" },
{"juan", "5300 cleasmer" },
{"Victor", "4200 terase" } };
int entries = 10;
char Name[10];
int entry_number;
int lookup (struct database employee[], char search[], int entries );
printf ("Name to search: ");
scanf ("%9s",Name);
entry_number = lookup (employee, Name, entries);
if (entry_number != -1)
printf ("%s\n", employee[entry_number].Address);
else
printf ("Name is not found.\n");
system("pause");
}