关于折半查找
#include <stdio.h>#define MAX 1000
int binsearch(int x,char v[],int n);
main()
{
char v[MAX];
int x,n;
scanf("%s%d%s",&x,&n,&v[MAX]);
binsearch(x,v[MAX],n);
printf("%d",binsearch(x,v[MAX],n));
}
int binsearch(int x,char v[],int n)
{
int low,high,mid;
low = 0;
high = n-1;
mid = (low+high)/2;
while (low<=high&&x!=mid)
{
if (x<mid)
high = mid;
else
low = mid;
}
if (x!=mid)
return -1;
else
return mid;
}
编译 0error4warning
:\c\3-1.c(9) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'char '
E:\c\3-1.c(9) : warning C4024: 'binsearch' : different types for formal and actual parameter 2
E:\c\3-1.c(10) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'char '
E:\c\3-1.c(10) : warning C4024: 'binsearch' : different types for formal and actual parameter 2
无法链接
我觉得错应该都在主函数。。