C strpbrk() Function

You are Here:

C strpbrk() Function

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; }

Output

First matching character: i New String: ikimass.com

Syntax

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

Parameter Values

ValueTypeExplanation
str1RequiredSpecifies an actual string
str2RequiredSpecifies a string of characters to be searched in str1.

Return Value

ValueExplanation
AddressReturns the pointer position to the first occurrence of the character (str2) in the string (str1).
NULLIf no occurrence of the character (str2) in the string (str1).

Reminder

Hi Developers, we almost covered 98% of String functions and Interview Question on C with examples for quick and easy learning.

We are working to cover every Single Concept in C.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author