strpbrk() — Find Characters in String
Format
#include <string.h>
char *strpbrk(const char *string1, const char *string2);
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
The strpbrk()
function
locates the first occurrence in the string pointed to by string1 of
any character from the string pointed to by string2.
Return Value
The strpbrk()
function
returns a pointer to the character. If string1 and string2 have
no characters in common, a NULL pointer is returned.
Example
This example returns a pointer to
the first occurrence in the array string of
either a or 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"
*/
Related Information
- strchr() — Search for Character
- strcmp() — Compare Strings
- strcspn() — Find Offset of First Character Match
- strncmp() — Compare Strings
- strrchr() — Locate Last Occurrence of Character in String
- strspn() — Find Offset of First Non-matching Character
- wcschr() — Search for Wide Character
- wcscspn() — Find Offset of First Wide-Character Match
- wcspbrk() — Locate Wide Characters in String
- wcsrchr() — Locate Last Occurrence of Wide Character in String
- wcswcs() — Locate Wide-Character Substring
- <string.h>