C Programming/string.h/strcspn
(Redirected from C Programming/C Reference/string.h/strcspn)
strcspn is the function from the C standard library (header file string.h).
It searches the string for certain set of characters.
The strcspn() function calculates the length of initial segment of string 1 which does not contain any character from string 2.
Return Value
editThis function returns the index of first character in string 1 that matches with any character of string2.
Syntax
edit#include <string.h>
size_t strcspn( const char *str1, const char *str2 );
Example
edit#include <stdio.h>
#include <string.h>
int main(){
char s[20] = "wikireader007", t[11] = "0123456789";
printf("The first decimal digit of s is at position: %d.\n", '''strcspn'''(s, t));
return 0;
}
Output:
The first decimal digit of s is at position: 10