#include <string.h>
size_t strspn( const char *str1, const char *str2 );
函数返回字符串str1中第一个不包含于字符串str2的字符的索引。
#include <stdio.h> #include <string.h> int main(void) { char *string1 = "1234567890"; char *string2 = "123DC8"; int length; length = strspn(string1, string2); printf("Character where strings differ is at position %d\n", length); return 0; }
输出结果:
Character where strings differ is at position 3