strpbrk() — Find characters in string

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3

both  

Format

#include <string.h>

char *strpbrk(const char *string1, const char *string2);

General description

Locates the first occurrence in the string pointed to by string1 of any character from the string pointed to by string2.

Returned value

If successful, strpbrk() returns a pointer to the character.

If string1 and string2 have no characters in common, strpbrk() returns a NULL pointer.

Example

CELEBS47
⁄* CELEBS47                                      

   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
The first occurrence of any of the characters "ab" in "A Blue Danube"
is "anube"

Related information