strcspn
Span the complement of a string
Description
The strcspn function spans the initial part of the null-terminated strings
as long as the characters from s
do not occur in string charset
(it spans the complement of charset
).
Example:
Example - Span the complement of a string
Workings
#include <stdio.h> #include <string.h> int main() { char s[20] = "abcde1010101", t[3] = "01"; printf("The first binary digit of s is at position: %d.\n", strcspn(s, t)); return 0; }
Solution
Output:
The first binary digit of s is at position: 5.