Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function – strcspn()

C Library Function - strcspn()

C Standard Library - <string.h> C Standard Library -

Description

C Library Function **size_t strcspn(const char *str1, const char *str2) ** retrieves the string str1 how many consecutive characters at the beginning do not contain the string str2 characters in .

Declaration

Below is the declaration of the strcspn() function.



size_t strcspn(const char *str1, const char *str2)

Parameters

Return Value

This function returns the number of consecutive characters at the beginning of str1 that do not contain characters from the string str2.

Example

The following example demonstrates the use of the strcspn() function.



#include 

#include 





int main ()

{

   int len;

   const char str1[] = "ABCDEF4960910";

   const char str2[] = "013";



   len = strcspn(str1, str2);



   printf("第一个匹配的字符是在 %d\n", len + 1);

   

   return(0);

}

Let's compile and run the above program, which will produce the following result:



第一个匹配的字符是在 10

C Standard Library - <string.h> C Standard Library -