YouTip LogoYouTip

C Function Strspn

# C Library Function - strspn() [![Image 3: C Standard Library - ](#) C Standard Library - ](#) ## Description The C library function **size_t strspn(const char *str1, const char *str2)** retrieves the index of the first character in string **str1** that is not present in string **str2**. ## Declaration Below is the declaration for the strspn() function. size_t strspn(const char *str1, const char *str2) ## Parameters * **str1** -- The C string to be scanned. * **str2** -- The string containing the list of characters to match in str1. ## Return Value This function returns the index of the first character in str1 that is not present in string str2. ## Example The following example demonstrates the usage of the strspn() function. ## Example #include #include int main () { int len; const char str1[]="ABCDEFG019874"; const char str2[]="ABCD"; len =strspn(str1, str2); printf("Initial segment matching length %dn", len ); return(0); } Let us compile and run the above program, which will produce the following result: Initial segment matching length 4 [![Image 4: C Standard Library - ](#) C Standard Library - ](#)
← C Function FeofC Function Strcmp β†’