strpbrk() in C Last Updated : 18 Sep, 2023 Comments Improve Suggest changes Like Article Like Report 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. C // C code to demonstrate the working of // strpbrk #include <stdio.h> #include <string.h> // Driver function int main() { // Declaring three strings char s1[] = "geeksforgeeks"; char s2[] = "app"; char s3[] = "kite"; char* r, *t; // Checks for matching character // no match found r = strpbrk(s1, s2); if (r != 0) printf("First matching character: %c\n", *r); else printf("Character not found"); // Checks for matching character // first match found at "e" t = strpbrk(s1, s3); if (t != 0) printf("\nFirst matching character: %c\n", *t); else printf("Character not found"); 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. C // C code to demonstrate practical application // of strpbrk #include <stdio.h> #include <string.h> // Driver function int main() { // Initializing victory string char s1[] = "victory"; // Declaring lottery strings char s2[] = "a23"; char s3[] = "i22"; char* r, *t; // Use of strpbrk() r = strpbrk(s1, s2); t = strpbrk(s1, s3); // Checks if player 1 has won lottery if (r != 0) printf("Congrats u have won"); else printf("Better luck next time"); // Checks if player 2 has won lottery if (t != 0) printf("\nCongrats u have won"); else printf("Better luck next time"); return (0); } Output: Better luck next time Congrats u have won Comment More infoAdvertise with us Next Article strrchr() in C S Shantanu Singh Improve Article Tags : C Language cpp-string C-Library Similar Reads strchr in C The strchr() function in C is a predefined function in the <string.h> library. It is used to find the first occurrence of a character in a string. It checks whether the given character is present in the given string. If the character is found, it returns the pointer to its first occurrence oth 3 min read strrchr() in C The strrchr() function in C locates the last occurrence of a character in a string and returns a pointer to it. It is a standard library function defined inside <string.h> header file. Syntax : char* strrchr( char* str, int chr ); Parameter: str: specifies the pointer to the null-terminated st 2 min read strcspn() in C The strcspn() is a part of the C standard library, it is defined in the <string.h> header file in C. The strcsspn function is used to find the number of characters in the given string before the 1st occurrence of a character from the defined set of characters or string. Syntax of strcspn()Cstr 3 min read strcspn() in C The strcspn() is a part of the C standard library, it is defined in the <string.h> header file in C. The strcsspn function is used to find the number of characters in the given string before the 1st occurrence of a character from the defined set of characters or string. Syntax of strcspn()Cstr 3 min read strcat() in C C strcat() function appends the string pointed to by src to the end of the string pointed to by dest. It will append a copy of the source string in the destination string. plus a terminating Null character. The initial character of the string(src) overwrites the Null-character present at the end of 2 min read snprintf() in C In C, snprintf() function is a standard library function that is used to print the specified string till a specified length in the specified format. It is defined in the <stdio.h> header file.In this article, we will learn about snprintf() function in C and how to use it in our program.SyntaxC 3 min read Like