标签:字符串查找
字符串查找两种情况,查找返回子字符串的指针位置和在字符串中的位置。
1.
const char* strstr(const char* src, const char* sub) { if (src == NULL && sub == NULL) { return src; } const char* ps = src; const char* pb = sub; while (*src) { do { if (!*ps) { return src; } } while (*pb++ == *ps++); src++; } return NULL; }2.
int myfind(const char* src, const char* sub) { if (src == NULL && sub == NULL) { return -1; } const char* ps; const char* pb; int rtn = 0; while (*src) { ps = src; pb = sub; do { if (!*pb) { return rtn; } } while (*pb++ == *ps++); src++; rtn++; } return NULL; }
标签:字符串查找
原文地址:http://blog.csdn.net/z702143700/article/details/46669821