search.c
上传用户:bjtelijie
上传日期:2010-01-01
资源大小:87k
文件大小:1k
- # include <stdio.h>
- # include <stdlib.h>
- # include <ctype.h>
- char *alpha = "abcdefghijklmnopqrstuvwxyz";
- int comp(const void *ch, const void *s);
- int main()
- {
- char ch;
- char *p;
- printf("Enter a character: ");
- ch = getchar();
- ch = tolower(ch); /* 将变元ch转换成小写字符 */
- p = (char *)bsearch(&ch, alpha, 26, 1, comp);
- if(p)
- printf("%c is in alphabetn", *p);
- else
- printf("is not in alphabetn");
- return 0;
- }
- int comp(const void *ch, const void *s)
- {
- return *(char *)ch -*(char *)s;
- }