函数名:memchr
头文件:<mem.h>
函数原型: void* memchr(void *s,char c,unsigned m);
功能:对于字符c搜索s区域的前m个字节
参数:viod* s 指向目标区域的指针
char c 为要搜索的字符
unsigned m 为要搜索的区域的前m个字节
返回值:返回指向字符c在s中第一次出现的位置的指针
程序例:从指定区域s中搜索特定的字符c,并将其位置输出。
#include<stdio.h> #include<mem.h> #include<string.h> int main(void){ char *s="I love www.dotcpp.com"; char c='w'; char *p=(char*)memchr(s,c,strlen(s)); if(p){ printf("You can find it:%s\n",p); }else{ printf("You can't find it\n"); } return 0; }
运行结果
You can find it:www.dotcpp.com
本文固定URL:https://www.dotcpp.com/course/490