strpbrk - C string.h

C examples for string.h:strpbrk

Type

function

From

<cstring> 
<string.h>

Description

Locate characters in string

Prototype

const char * strpbrk ( const char * str1, const char * str2 );
      char * strpbrk (       char * str1, const char * str2 );

Parameters

Parameter Description
str1 C string to be scanned.
str2 C string containing the characters to match.

Return Value

A pointer to the first occurrence in str1 of any of the characters that are part of str2.

If none of the characters of str2 is present in str1, a null pointer is returned.

Demo Code

#include <stdio.h>
#include <string.h>

int main ()/*from w ww . j  av  a  2 s .c  om*/
{
  char str[] = "This is a sample string";
  char key[] = "aeiou";
  char * pch;
  printf ("Vowels in '%s': ",str);
  pch = strpbrk (str, key);
  while (pch != NULL)
  {
    printf ("%c " , *pch);
    pch = strpbrk (pch+1,key);
  }
  printf ("\n");
  return 0;
}

Related Tutorials