![]() |
VOOZH | about |
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.
where,
This function returns the number of characters in the first string before the 1st occurrence
of character present in second string.
These C programs demonstrate the use of strcspn() for various scenarios.
str1: geeksforgeeks str2: kfc The number of characters in str1 before first matched character from str2: 3
Rules : In this game, 2 players play and one player initially generated a string and is asked to produce a string which has as many unmatched characters. After 1 round, player producing string with maximum unmatched characters wins.
Match Drawn!! Score: 2
In this program the strcspn() is used to check if the string is valid, a valid string must not contain any special character like "!@#$%&*".
String: geeksforgeeks Valid String String: geeks@geeks Invalid String: Contains prohibited special characters