Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150099
  • 博文数量: 42
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 39
  • 用 户 组: 普通用户
  • 注册时间: 2016-01-07 14:06
文章分类

全部博文(42)

文章存档

2017年(1)

2016年(41)

分类: C/C++

2016-01-20 15:38:47

原文地址:C语言实例66:查找函数 作者:hnrainll

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

char *alpha = "abcdefghikjklmnopqrstuvwxyz";

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

int main(int argc, char *argv[])
{
    char ch;
    char *p;

    printf("Enter a character: ");
    ch = getchar();
    ch = tolower(ch);
    p = (char *)bsearch(&ch, alpha, 26, 1, comp);
    if(p)
        printf("%c is in alphabet\n", *p);

    system("pause");
    return 0;
}

int comp(const void *ch, const void *s)
{
    return *(char *)ch - *(char *)s;
}


阅读(1226) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~