C - strspn() function
C strspn() function - Get length of a substring
Syntax:
size_t strspn(const char *str1, const char *str2)
The strspn() function is used to compute the length (in bytes) of the maximum initial segment of the string pointed to by str1 which consists entirely of bytes from the string pointed to by str2.
Parameters:
Name | Description | Required /Optional |
---|---|---|
str1 | Null-terminated string to search. | Required |
str2 | Null-terminated character set. | Required |
Return value from strspn()
- The strspn() function shall return the computed length.
- No return value is reserved to indicate an error.
Example: strspn() function.
Output:
The first 5 characters of "Programming" are found in "Pogr" The first 1 characters of "Programming" are found in "Po" The first 3 characters of "Programming" are found in "Por" The first 3 characters of "Programming" are found in "Porm" The first 0 characters of "Programming" are found in "orm"
C Programming Code Editor:
Previous C Programming: C strrchr()
Next C Programming: C strstr()