strpbrk ()- 尋找字串中的字元
格式
#include <string.h>
char *strpbrk(const char *string1, const char *string2);語言層次
ANSI
安全執行緒
是
區分語言環境
此函數的行為可能受現行語言環境的 LC_CTYPE 種類影響。 如需相關資訊,請參閱 瞭解 CCSID 及語言環境。
說明
strpbrk() 函數會從 string2所指向的字串中,尋找 string1 所指向之字串中第一個出現的字元。
回覆值
strpbrk() 函數會傳回字元的指標。 如果 string1 和 string2 沒有共同的字元,則會傳回 NULL 指標。
範例
此範例會傳回一個指標,指向陣列 字串 中第一個出現的 a 或 b。
#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"
*/