Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function – strpbrk()

C Library Function - strpbrk()

C Standard Library - <string.h> C Standard Library -

Description

C Library Function **char *strpbrk(const char *str1, const char *str2) ** searches the string str1 for the first character that matches a character in the string str2 characters, not including the null terminator. That is, the characters in the string str1 are checked one by one; when the checked character is also contained in the string str2, the check stops and the position of that character is returned.

Declaration

Below is the declaration of the strpbrk() function.



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

Parameters

Return Value

This function returns the number of the first character in str1 that matches a character in the string str2; if no character is found, it returns NULL.

Example

The following example demonstrates the use of the strpbrk() function.

Example

#include

<

stdio.h

#include

<

string.h

int

main

(

)

{

const

char

str1

[

]

=

"

abcde2fghi3jk4l

"

;

const

char

str2

[

]

=

"

34

"

;

char

ret

;

ret

=

strpbrk

(

str1

,

str2

)

;

if

(

ret

)

{

printf

(

"

The first matching character is: %c

\

n

"

, *

ret

)

;

}

else

{

printf

(

"

Character not found

"

)

;

}

return

(

0

)

;

}

Let's compile and run the above program, which will produce the following result:



第一个匹配的字符是: 3

C Standard Library - <string.h> C Standard Library -