C strpbrk() Function

Last Updated:

C strpbrk()

The strpbrk() function searches the first occurrence of the character in a given string and then it displays the string starting from that character.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { char str1[] = "wikimass.com"; char str2[] = "msi"; char *ptr; ptr = strpbrk(str1, str2); if(ptr) { printf("First matching character: %c\n", *ptr); printf("New String: %s", ptr); } else { printf("Character not found"); } return 0; }

Syntax

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

Parameter Values

ValueTypeExplanation
str1 Required Specifies an actual string
str2 Required Specifies a string of characters to be searched in str1.

Return Value

ValueExplanation
Address Returns the pointer position to the first occurrence of the character (str2) in the string (str1).
NULL If no occurrence of the character (str2) in the string (str1).

Share this Page

Meet the Author