The strspn () function in C
Function size_t strspn (const char * str1, const char * str2) calculates the length of the first character segment of the str1 string containing the characters in str2
Function size_t strspn (const char * str1, const char * str2) calculates the length of the first character segment of the str1 string containing the characters in str2
Declaring the function strspn () in C
Here is the declaration for strspn () in C:
size_t strspn ( const char * str1 , const char * str2 )
Parameters
str1 - Chain to be scanned.
str2 - String containing characters to match in str1.
Returns the value
This function returns the number of characters in the string segment of the original str1 string, but only the characters in str2.
For example
The following C program illustrates the usage of strspn () in C:
#include #include int main () { int len ; const char str1 [] = "ABCDEFG019874" ; const char str2 [] = "ABCD" ; len = strspn ( str1 , str2 ); printf ( "Do dai cua chuoi ket noi dau tien la = %dn" , len ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: The function strrchr () in C
Next lesson: Strstr () function in C
You should read it
- The strtok () function in C
- The strlen () function in C
- The strchr () function in C
- The strerror () function in C
- Memset () function in C
- The strrchr () function in C
- Function in programming C
- Beginners of computer programming need to focus on what?
- Strcpy () function in C
- Memmove function in C
- Top 20 free programming learning websites need to bookmark immediately!
- The strcoll () function in C
Maybe you are interested
Admire incredibly detailed images of the Orion Nebula through the eyes of the James Webb telescope This star 'tears up' its companion to create a rare beautiful nebula Admire the moment millions of new stars are born in the Lupus 3 nebula Top 15 free games on Steam gamers should experience Before 'returning to Thanos', what was the fate and appearance of Nebula in the comics? Spectacular views on Google Sky