Professional Documents
Culture Documents
Tutorials
Student
Jobs
Courses
Write
Come write articles for us and get featured
Practice
Learn and code with the best industry experts
Premium
Get access to ad-free content, doubt assistance and more!
Jobs
Come and find your dream job with us
o Geeks Digest
o Quizzes
o Geeks Campus
o Gblog Articles
o IDE
o Campus Mantri
My Profile Edit Profile
Logout
Home
Courses
o Practice DS & Algo.
o Algorithms
o Analysis of Algorithms
o Data Structures
o Interview Corner
o Languages
o ISRO CS
o GATE
o CS Subjects
o Web Technologies
o School Learning
o Mathematics
o Maths Notes (Class 8-11)
o NCERT Solutions
o RD Sharma Solutions
o UGC NET CS
o Student
o Jobs
GBlog
Puzzles
What's New ?
Change Language
Related Articles
Related Articles
Strings in C
How to Append a Character to a String in C
strncat() function in C/C++
strpbrk() in C
strcoll() in C/C++
ispunct() function in C
strspn() function in C
isalpha() and isdigit() functions in C with cstring examples.
static_cast in C++ | Type Casting operators
const_cast in C++ | Type Casting operators
reinterpret_cast in C++ | Type Casting operators
Type Conversion in C++
Converting Strings to Numbers in C/C++
Converting string to number and vice-versa in C++
How to find size of array in C/C++ without using sizeof ?
array::size() in C++ STL
What are the default values of static variables in C?
Understanding “volatile” qualifier in C | Set 2 (Examples)
Const Qualifier in C
Initialization of static variables in C
Understanding “register” keyword in C
Understanding “extern” keyword in C
Storage Classes in C
Static Variables in C
Memory Layout of C Programs
What is Memory Leak? How can we avoid?
std::sort() in C++ STL
Arrays in C/C++
Bitwise Operators in C/C++
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
strpbrk() in C
Difficulty Level : Easy
Last Updated : 02 May, 2018
This function finds the first character in the string s1 that matches any character
specified in s2 (It excludes terminating null-characters).
Syntax :
char *strpbrk(const char *s1, const char *s2)
Parameters :
s1 : string to be scanned.
s2 : string containing the characters to match.
Return Value :
It returns a pointer to the character in s1 that
matches one of the characters in s2, else returns NULL.
// strpbrk
#include <stdio.h>
#include <string.h>
// Driver function
int main()
char* r, *t;
if (r != 0)
else
if (t != 0)
printf("\nFirst matching character: %c\n", *t);
else
return (0);
Output:
Character not found
First matching character: e
Practical Application
This function can be used in game of lottery where the person having string with letter
coming first in victory wins, i.e. this can be used at any place where first person wins.
// of strpbrk
#include <stdio.h>
#include <string.h>
// Driver function
int main()
char* r, *t;
if (r != 0)
else
if (t != 0)
else
printf("Better luck next time");
return (0);
Output:
Better luck next time
Congrats u have won
This article is contributed by Shantanu Singh. If you like GeeksforGeeks and would
like to contribute, you can also write an article using contribute.geeksforgeeks.org or
mail your article to contribute@geeksforgeeks.org. See your article appearing on the
GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more
information about the topic discussed above.
Want to learn from the best curated videos and practice problems, check out the C
Foundation Course for Basic to Advanced C.
Like6
Previous
strncat() function in C/C++
Next
strcoll() in C/C++
ADVERTISEMENT BY ADRECOVER
RECOMMENDED ARTICLES
Page :
1
2
Program to perform a letter frequency attack on a monoalphabetic substitution cipher
22, Jul 21
20, Jul 21
20, Jul 21
20, Jul 21
20, Jul 21
19, Jul 21
19, Jul 21
19, Jul 21
Article Contributed By :
GeeksforGeeks
Vote for difficulty
Improved By :
SACHIN KUNTE
Article Tags :
C-Library
cpp-string
C Language
C++
Practice Tags :
CPP
Improve Article
Report Issue
ADS BY ADRECOVER
WHAT'S NEW
Competitive Programming Live Classes for Students
View Details
View Details
View Details
ADS BY ADRECOVER
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Load Comments
ADVERTISEMENT BY ADRECOVER
Company
About Us
Careers
Privacy Policy
Contact Us
Copyright Policy
Learn
Algorithms
Data Structures
Languages
CS Subjects
Video Tutorials
Practice
Courses
Company-wise
Topic-wise
How to begin?
Contribute
Write an Article
Write Interview Experience
Internships
Videos
@geeksforgeeks , Some rights reserved