标签:
//模拟实现库函数strstr,查找子字符串 #include <stdio.h> #include <assert.h> char * my_strstr( char *dst, const char * src) { assert(dst); assert(src); int i, j, k; for (i = 0; dst[i] != '\0'; i++) { for (j = i, k = 0; src[k] != '\0'&&dst[j] == src[k]; j++, k++) { ; } if (src[k] == '\0'&&k > 0) return &dst[i]; } return NULL; } int main() { char *p1 = "abcdef"; char *p2 = "cde"; printf("%s\n", my_strstr(p1, p2)); return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/doudouwa1234/article/details/46753463