The strcspn() function in C/C++ takes two string as input, string_1 and string_2 as it’s argument and searches string_1 by traversing for any characters that is present in string_2 . The function will return the length of string_1 if none of the characters of string_2 are found in string_1 . This function is defined in cstring header file .
size_t strcspn ( const char *string_1, const char *string_2 )
Parameters : The function accepts two mandatory parameters which are described below:
- string_1: specifies the string to be searched
- string_2: specifies the string containing the characters to be matched
Return Value : This function returns the number of character traversed in string_1 before any of the character matched from string_2 .
Below programs illustrate the above function:
The number of characters beforethe matched character are 12
geekforgeeks456 didn't matched any character from string_2
- strcspn() in C
- Function Overloading vs Function Overriding in C++
- How to call some function before main() function in C++?
- What happens when a virtual function is called inside a non-virtual function in C++
- Difference between Virtual function and Pure virtual function in C++
- log() function in C++
- exp() function C++
- div() function in C++
- arc function in C
- fma() function in C++
- valarray log() function in C++
- map key_comp() function in C++ STL
- max() function for valarray in C++
- map rbegin() function in C++ STL
- map rend() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.