Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strpbrk - Search for a character in a string

&pagelevel(4)&pagelevel

Definition

#include <string.h>

char *strpbrk(const char *s1, const char *s2);

strpbrk searches string s1 for the first character matching any character in string s2. The
terminating null byte (\0) is not considered part of string s2.

Return val.

Pointer to the first matching character found in s1


if successful.

NULL pointer

if not a single match is present.

Notes

Strings terminated with the null byte (\0) are expected as arguments.

The following two prototypes of the strpbrk function are applicable to C++:
const char *strpbrk(const char *s1, const char *s2);

          char *strpbrk( char *s1, const char *s2);

Example

#include <string.h>
#include <stdio.h>
int main(void)
{
  char text1[40];
  static char text2[] = "0123456789";
  char *result;
  printf("Example of strpbrk()\n");
  printf("Please enter a string (max. 40 characters) !\n");
  scanf("%s",text1);
  result = strpbrk(text1,text2);
  if(result == NULL)
    printf("The entered string does not contain any digits.\n");
  else printf("%s\n", result);
  return 0;
}

See also

index, strchr