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
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
4.5 ★ | 2 Vote
You should read it
May be interested
- The strtok () function in Cchar * strtok function (char * str, const char * delim) divides the string str into a sequence of tokens separately separated by delim separators (eg comma, ...).
- Function strxfrm () in Cthe function size_t strxfrm (char * dest, const char * src, size_t n) transforms the first n characters of the src string into the current locale and places them in dest string.
- The function printf () in Cthe printf () function in the standard c library sends formatted output to a stdout.
- time.h in Cthe file header named time.h in standard library c defines four variable types, two macros and various functions for date and time operations.
- The function getenv () in Cchar * getenv (const char * name) function searches the environment string pointed to by the name parameter and returns the value associated with that string.
- System () function in Cthe int system (const char * command) function passes the command name or program name specified by the command to the host environment to be executed by the command processor and returned after the command is completed.