您的位置:首页 > 编程语言 > C语言/C++

C语言调用库函数实现二分查找

2010-11-13 12:10 567 查看
/*
* main.c
*
* Created on: Oct 29, 2010
* Author: jenson
*/

#include <stdio.h>
#include <stdlib.h>

int cmp(const void *ch,const void *s);

int main(){
char ch;
char *p;
printf("Enter a character:");
ch = getchar();
ch = tolower(ch);
p = (char *)bsearch(&ch,"abcdefghijklmnopqrstuvwxyz",26,1,cmp);
if(p){
printf("%c is found\n",ch);
}else{
printf("%c is not found.\n",ch);
}
return 0;
}
int cmp(const void *ch,const void *s){
return *(char *)ch - *(char *)s;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 算法 休闲