strspn 库函数用于统计字符串开头的子字符串在指定字符串中的字符的个数。
- #include <stdio.h>
-
-
int strspn_test(const char *s, const char *accept);
-
-
int
-
main(int argc, char **argv)
-
{
-
char *s = "hello andy";
-
char *a = "where";
-
-
printf("Result: %d\n", strspn_test(s,a));
-
-
return 0;
-
}
-
-
int
-
strspn_test(const char *s, const char *accept)
-
{
-
const char *p;
-
const char *a;
-
int count = 0;
-
-
for (p = s; *p != '\0'; ++p) {
-
for (a = accept; *a != '\0'; ++a) {
-
if (*p == *a) {
-
break;
-
}
-
}
-
if (*a == '\0') {
-
return count;
-
}
-
++count;
-
}
-
-
return count;
-
}
阅读(288) | 评论(0) | 转发(0) |