The C library function strcspn() calculates the length of the number of characters before the 1st occurrence of character present in both the string.
strcspn(const char *str1, const char *str2) Parameters: str1 : The Target string in which search has to be made. str2 : Argument string containing characters to match in target string. Return Value: This function returns the number of characters before the 1st occurrence of character present in both the string.
The unmatched characters before first matched character : 3
Practical Application : There can be many practical application of this function, be it word games or irregularity calculator. A simple word game is demonstrated in this article.
Rules : According to 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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.