hey guys. to the guys who helped with my earlier prob about a bubble sort, this is kind of a continuation (although i couldn't solve my probs, i'll seek help at school tomorrow).
heres the prob. got a 200 customer record structure consisting of first name, last name, address, start and end.
thats fine, and the early problems i was able to handle by myself. now i need to do a binary search which will read a last name and search for a matching last name within my customer records. this is the code which i came up with. it doesnt work but i am hopeful that i am not far off.
Code:
char searchCust(struct customers cust[])
{
int item, location;
char searchCust, nums = cust[NUMEL].recSurName[11];
system("cls");
printf("Please enter the surname of the customer: ");
scanf("%s", searchCust);
location = binarySearch(nums, NUMEL, item);
if (location >-1)
{
printf("The item was found at index location %d\n", location);
}
else
{
printf("The item was not found in the array\n");
}
return location;
}
int binarySearch(int list[], int size, int key)
{
int index, found, left, right, midpoint;
index = -1;
found = FALSE;
left = 0;
right = size - 1;
while (left <= right && !found)
{
midpoint = (int)((left + right)/2);
if (key == list [midpoint])
{
found = TRUE;
index = midpoint;
}
else if (key > list[midpoint])
{
left = midpoint + 1;
}
else
{
right = midpoint - 1;
}
}
return(index);
}
i got an error in this line
Code:
location = binarySearch(nums, NUMEL, item);
it says : error C2664: 'binarySearch' : cannot convert parameter 1 from 'char' to 'int []'
i tried changing alot of things but i don't actually know what i need to change (i've seen similar errors and eliminated them quickly in the past).
thanks alot for your time, and your help.