strpbrk ()- 查找字符串中的字符

格式

#include <string.h>
char *strpbrk(const char *string1, const char *string2);

语言级别

ANSI

线程安全

语言环境敏感

此函数的行为可能受当前语言环境的 LC_CTYPE 类别影响。 有关更多信息,请参阅 了解 CCSID 和语言环境

描述

strpbrk() 函数查找由 string1 指向的字符串中首次出现的由 string2指向的字符串中的任何字符。

返回值

strpbrk() 函数返回一个指向该字符的指针。 如果 string1string2 没有公共字符,那么将返回 NULL 指针。

示例

此示例返回一个指针,该指针指向 ab的数组 string 中的第一个实例。
#include <stdio.h>
#include <string.h>
 
int main(void)
{
   char *result, *string = "A Blue Danube";
   char *chars = "ab";
 
   result = strpbrk(string, chars);
   printf("The first occurrence of any of the characters \"%s\" in "
          "\"%s\" is \"%s\"\n", chars, string, result);
}
 
/*****************  Output should be similar to:  *****************
 
The first occurrence of any of the characters "ab" in "The Blue Danube"
is "anube"
*/

相关信息