求c语言大神帮我看看这个二分法查找有什么问题 刚输入就结束了这个函数
intSearchSNUM(Studentteam[],intn)//定义学号查找{chark[20];printf("请输入你需要查找的学号:\n");scanf("%...
int SearchSNUM(Student team[],int n)//定义学号查找
{
char k[20];
printf("请输入你需要查找的学号:\n");
scanf("%s",&k);
int low=0,high=n-1,mid;
do
{
fflush(stdin);
mid = (low high)/2;
if(k==team[mid].SNUM)
{
printf("学号为:%d\t",team[mid].SNUM);
printf("姓名为:%s\t",team[mid].NAME);
printf("房号为:%s\n",team[mid].RNUM);
return mid 1;
}
if(k<team[mid].SNUM)
{
high = mid-1;
}
else
{
low = mid 1;
}
}while(low<high); 展开
{
char k[20];
printf("请输入你需要查找的学号:\n");
scanf("%s",&k);
int low=0,high=n-1,mid;
do
{
fflush(stdin);
mid = (low high)/2;
if(k==team[mid].SNUM)
{
printf("学号为:%d\t",team[mid].SNUM);
printf("姓名为:%s\t",team[mid].NAME);
printf("房号为:%s\n",team[mid].RNUM);
return mid 1;
}
if(k<team[mid].SNUM)
{
high = mid-1;
}
else
{
low = mid 1;
}
}while(low<high); 展开
1个回答
展开全部
int SearchSNUM(Student team[],int n)//定义学号查找
{ char k[20];
printf("请输入你需要查找的学号:\n");
scanf("%s",&k);
int low=0,high=n-1,mid;
do
{ fflush(stdin);
mid = (low+high)/2;
if(strcmp(k,team[mid].SNUM)==0) //需包含string.h
{ printf("学号为:%d\t",team[mid].SNUM);
printf("姓名为:%s\t",team[mid].NAME);
printf("房号为:%s\n",team[mid].RNUM);
return mid+1;
}
if(strcmp(k,team[mid].SNUM)<0)
{ high = mid-1;
}
else
{ low = mid+1;
}
}
while(low<high);
return -1;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询