//查找子串
#include<stdio.h>
char* Search(char* str1, char* str2) {
char* s1 = str1;
char* s2 = str2;
char* cur = str1;
while (*cur) {
s1 = cur;
s2 = str2;
while (*s1 && *s2 && (*s1 == *s2)) {
s1++;
s2++;
}
if (*s2 == '\0') {
return cur;
}
cur++;
}
return NULL;
}
int main() {
char str1[] = "abcababcabc";
char str2[] = "abcabc";
char* isTure= Search(str1,str2);
if (isTure == NULL) printf("没找到\n");
else printf("找到了\n");
return 0;
}
在字符串中查找子字符串
最新推荐文章于 2023-01-08 12:34:59 发布