Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1396125
  • 博文数量: 143
  • 博客积分: 10005
  • 博客等级: 上将
  • 技术积分: 1535
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-23 17:25
个人简介

淡泊明志 宁静致远

文章分类

全部博文(143)

文章存档

2011年(2)

2009年(1)

2007年(22)

2006年(118)

我的朋友

分类: C/C++

2006-11-25 13:13:03

C语言库函数源代码】

【本程序在Dev C++ 4.9.9.2 下编译通过】

#include

/*

   Searches at bufferfor the given character, stopping when characteris first found or cnt bytes have been searched through.

   从buffer所指内存区域的前count个字节查找字符ch,当第一次遇到字符ch时停止查找。如果成功,返回指向字符ch的指针;否则返回NULL。

*/

 

void * my_memchr(const void * buffer,int ch,int count)

{

   while ( count && (*(unsigned char *)buffer != (unsigned char)ch) )

   {

      buffer = (unsigned char *)buffer + 1;

        count--;

   }

   return(count ? (void *)buffer : NULL);

}

int main()

{

   char *str = "ammana_babi";

   char * p;

   char ch;

  

   ch = '9';

   p = (char *)my_memchr(str,ch,strlen(str)+1);

   if(p == NULL)

      printf("Can't find the character %c !\n",ch);

   else

      printf("Find the character %c !\n",*p);

  

   ch = 'b';

   p = (char *)my_memchr(str,ch,strlen(str)+1);

   if(p == NULL)

      printf("Can't find the character %c !\n",ch);

   else

      printf("Find the character %c !\n",*p);

 

   system("pause");

   return 0;

}

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