欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
memchr函數(shù)實現(xiàn)及簡單使用
[打印本頁]
作者:
xiaojuan
時間:
2014-9-24 22:36
標題:
memchr函數(shù)實現(xiàn)及簡單使用
//:Vc++6.0 String memchr函數(shù)
//功能:查找里面第一個和目標字符匹配的字符
//參數(shù):ptr 首地址 value 想要查找的字符值 num 查到那個地址
//返回值:如果成功,返回指向字符的指針;否則返回NULL
#include<stdio.h>
const void *memchr (const void *ptr, int value, int num);
int main(void)
{
char * pch;
char str[] = "hello world";
pch = (char*) memchr (str, 'e', 12);
if (pch!=NULL)
printf ("'e' found at position %d.\n", pch - str + 1);
else
printf ("'e' not found.\n");
return 0;
}
const void *memchr (const void *ptr, int value, int num)
{
if (ptr == NULL)
{
perror("ptr");
return NULL;
}
char * p = (char *)ptr;
while (num--)
{
if (*p != (char)value)
p++;
else
return p;
}
return NULL;
}
//在vc++6.0中的運行結(jié)果為:'e' found at position 2.
//注:在VC++6.0中函數(shù)只能比較字符串//:~
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1