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

C Library Function - strspn()

C Library Function - strspn()

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

Description

C Library Function **size_t strspn(const char str1, const char str2) Search the string str1 for the first character that is not in the string str2 the index of the character that appears.

Declaration

Below is the declaration of the strspn() function.



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

Parameters

Return Value

This function returns the index of the first character in str1 that does not appear in the string str2.

Example

The following example demonstrates the use 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 match length %d\n"

,

len

)

;

   

   

return

(

0

)

;

}

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



初始段匹配长度 4

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