标签:
如题
http://blog.csdn.net/hxz_qlh/article/details/14110221
代码来自非原创
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 char *strstring(char *ParentString,char *SubString) 7 { 8 char *pSubString,*pParentString; 9 for(char *pTmp = ParentString; *pTmp !=‘\0‘ ; pTmp++) 10 { 11 pSubString = SubString; 12 pParentString = pTmp; 13 while(*pSubString != ‘\0‘ && *pSubString == *pParentString) 14 { 15 pSubString++; 16 pParentString++; 17 } 18 if(*pSubString == ‘\0‘) 19 { 20 return pTmp; 21 } 22 } 23 return NULL; 24 } 25 26 int main() 27 { 28 cout << "Hello world!" << endl; 29 char *ParentString = "I love TrendMicro!"; 30 char *SubString = "Trend"; 31 printf("%s\n",strstring(ParentString,SubString)); 32 return 0; 33 }
给你两个字符串str1,str2,找出str2在str1中的位置
标签:
原文地址:http://www.cnblogs.com/njczy2010/p/5187186.html