C++ strpbrk() Function

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.

This function is defined in <cstring> header file.


C++ Compiler
#include <iostream> #include <cstring> using namespace std; int main() { char str1[] = "wikimass.com"; char str2[] = "msi"; char *ptr; ptr = strpbrk(str1, str2); if(ptr) { cout << "First matching character: " << *ptr; cout << "\nNew String: " << ptr; } else { cout << "Character not found"; } return 0; }


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

Parameter Values

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

Return Value

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).

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