标签:在父字符串中查找子字符串
在父字符串中查找子字符串(指针控制,也可选择标控制)
#pragma once #include<iostream> #include<assert.h> using namespace std; char* StrStr(char* source, char* dest) { assert(source&&dest); if (strlen(source) < strlen(dest)) return NULL; char* newSrc = NULL; char* newDest = dest; while (*source) { newSrc = source; while (*source&&*dest&&*source == *dest) { source++; dest++; } if (*dest == ‘\0‘) { return newSrc; } dest = newDest; source = newSrc + 1; } } void Test1() { char* src = "abcbcdef"; char* dest = "bcd"; cout << StrStr(src, dest) << endl; }
指针追踪截图
本文出自 “小止” 博客,请务必保留此出处http://10541556.blog.51cto.com/10531556/1755336
标签:在父字符串中查找子字符串
原文地址:http://10541556.blog.51cto.com/10531556/1755336