strpbrk 库函数用于在字符串中查找首次出现指定字符集中字符的子字符串。
- #include <stdio.h>
-
-
char *strpbrk_test(const char *cs, const char *ct);
-
-
int
-
main(int argc, char **argv)
-
{
-
char *s = "hello andy";
-
char *t = "la";
-
-
printf("Result: %s\n", strpbrk_test(s, t));
-
-
return 0;
-
}
-
-
char*
-
strpbrk_test(const char *cs, const char *ct)
-
{
-
const char *sc1, *sc2;
-
-
for (sc1 = cs; *sc1 != '\0'; ++sc1) {
-
for (sc2 = ct; *sc2 != '\0'; ++sc2) {
-
if (*sc1 == *sc2) {
-
return (char *)sc1;
-
}
-
}
-
}
-
-
return NULL;
-
}
注:return (char *)sc1;
阅读(292) | 评论(0) | 转发(0) |