strchr函数原型

char *strchr(char const *str,int ch);

功能

查找str字符串中第一个出现ch的地方,并且返回它的位置。

程序

#include <string.h>
int main()
{
char *a = "hello liming";
char *b;
b = strchr(a,'l');
printf("%s",b);
return 0;

}

测试结果’

llo liming

strrchr函数原型

char *strrchr(char const *str,int ch);

功能

查找str字符串中最后一个出现ch的地方,并且返回它的位置。

程序

#include <string.h>
int main()
{
char *a = "hello liming";
char *b;
b = strchr(a,'l');
printf("%s",b);
return 0;

}

测试结果

liming

strpbrk函数

功能

查找任何一组字符第一次在字符串中出现的位置。

函数原型

char *strpbrk(char const *str,char const *group);

这个函数返回一个指向str中第一个匹配group中任何一个字符的字符位置。如果未找到匹配函数返回一个NULL指针。

查找一个字符串函数_strchr和strrchr-编程之家

ans所指向的位置是sring+1,因为这个位置是第2个参数的字符第一次出现的位置,和前面一样,这个函数也是区分大小写的。