如何修复此搜索方法?这部分是一个switch语句,要求用户搜索客户端ID。
case 2: printf("Enter the client ID to search for: ");
scanf("%d", searchID);
searchClient(searchID, pcli, clCount);
foundAt = searchClient(searchID, pcli, clCount);
if(foundAt >= 0)
printf("%d is found at position %d in the array", searchID, foundAt);
else
printf("%d is not found anywhere", searchID);
break;
这是在案例2中调用的搜索方法本身
int searchClient(char* searchID, client* pcli, int clCount)
{
int i = 0;
for(i = 0; i < clCount; i++)
{
if(strcmp(searchID,(pcli + i)->clID)==0)
{
return i;
}
}
return -1;
}//end searchClient
答案 0 :(得分:1)
搜索函数需要一个字符串,但是你给它一个整数, perhps更改输入对话框如下:
printf("Enter the client ID to search for: ");
{
char mybuffer[100];
scanf("%99s", mybuffer);
foundAt = searchClient(mybuffer, pcli, clCount);
}