strpbrk - search a string for any of a set of bytes
所需头文件
#include <string.h>
char *strpbrk(const char *s, const char *accept);
The strpbrk() function locates the first occurrence in the string s of any of the bytes in the string accept.
The strpbrk() function returns a pointer to the byte in s that matches one of the bytes in accept, or NULL if no such byte is found.
strpbrk函数定位字符串s中第一次出现字符串accept中的字节的位置
运行结果如下:
所需头文件
#include <string.h>
char *strpbrk(const char *s, const char *accept);
The strpbrk() function locates the first occurrence in the string s of any of the bytes in the string accept.
The strpbrk() function returns a pointer to the byte in s that matches one of the bytes in accept, or NULL if no such byte is found.
strpbrk函数定位字符串s中第一次出现字符串accept中的字节的位置
strpbrk函数返回指向s中第一次出现accept中字节的问题,如果没有这个字节则返回NULL
testcase如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
const char *dest = "abc12cba";
const char *accept1 = "xyz12";
const char *accept2 = "xyz";
char *tmp = NULL;
tmp = strpbrk(dest, accept1);
printf("tmp = %s\n", tmp);
tmp = strpbrk(dest, accept2);
if (tmp == NULL) {
printf("tmp is null\n");
}
return 0;
}
运行结果如下:
cheny.le@cheny-ThinkPad-T420:~/cheny/testCode$ ./a.out
tmp = 12cba
tmp is null
这个函数的主要功能就是在一个字符串中查找指定的字符集