C programming strpbrk string.h

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

s1 -The first string.

s2 -The second string.

Return type
char* -The pointer to the first character that match in the string address by ‘s1’ matching any character of the string address by s2.If no character of s2 matched in s1 NULL pointer is returned.

In C programming the <string.h> strpbrk function returns the first occurrence of the character in string ‘s1’ that match any of the character in ‘s2’.This function is similar with ‘strcpsn’ but ‘strcspn’ returns the index value of the character in s1 matching any character of ‘s2’.Read more about ‘strcspn’ function form the link given below.

Link : C strcspn string.h

Code example

char s1[]=”New” , s2[]=”Name” , s3[]=”mAn” , *ret ;

ret=strpbrk(s1, s2);

printf(“ret=%c”, *ret);

ret=strpbrk(s1 , s3);

/* printf(“ret=%c”, *ret); //this pass an exception since we are trying to access a NULL pointer */



The first character of s2 ‘N’ matches the first character of ‘s1’ so ‘ret’ points to ‘N’ character.

Related links

->C strrchr string.h

->C strchr string.h

->C strspn string.h

->C strstr string.h

->C strtok string.h