Pointer to the null-terminated string to be scanned.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to the null-terminated string containing characters to match against `str1`.
Read more about parameters of strcspn in parameters section
The strcspnfunction in C language Scans the first string for the first occurrence of any of the characters in the second string.
The strcspn function calculates the length of the initial segment of str1 which consists entirely of characters not in str2. In other words, it returns the index of the first occurrence in str1 of any of the characters in str2, or the length of str1 if none of the characters in str2 are found in str1.
The strcspnfunction takes 2
parameters:
•
const char * `str1`: Pointer to the null-terminated string to be scanned.
•
const char * `str2`: Pointer to the null-terminated string containing characters to match against `str1`.
Calculates the length of the initial segment of `str1` that consists entirely of characters not found in `str2`. Returns the number of characters in this segment as a `size_t`.
The strcspn function return value :
Returns the number of characters in the initial segment of str1 which are not in str2
Output
This example demonstrates basic usage of strcspn to find the first occurrence of any punctuation mark in a string.