当前位置: C语言 -- 标准库 -- <string.h> -- strpbrk

strpbrk函数


概要:
#include <string.h>
char *strpbrk(const char *s1, const char *s2);

描述:

该函数搜索参数s2指向字符串中的任意字符在参数s1指向字符串中第一次出现的位置。


参数:
const char *s1

指向字符串的指针。

const char *s2

指向字符串的指针。


返回值:

如果存在匹配字符,函数返回指向该字符的指针;如果不存在匹配字符,函数返回空指针。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
/*函数strpbrk范例*/

#include <stdio.h>
#include <string.h>

int main(void)
{
    const char str[] = "There is no rose without a thorn.";
    char *pch;

    pch = strpbrk(str, "aeiou");
    printf("The position of the first occurrence: %td\n", (pch-str+1));
    
    return 0;
}


输出:

The position of the first occurrence: 3


相关内容:
memchr 搜索指定字符在内存区域第一次出现位置的函数。
strchr 搜索指定字符在字符串中第一次出现位置的函数。
strcspn 计算最大初始片段长度的函数。
strrchr 搜索指定字符在字符串中最后一次出现位置的函数。
strspn 计算最大初始片段长度的函数。
strstr 搜索子字符串在字符串中第一次出现位置的函数。
strtok 拆分字符串的函数。