实现strstr功能(寻找子串在父串中首次出现的位置)

admin2019-03-29  81

问题 实现strstr功能(寻找子串在父串中首次出现的位置)

选项

答案char * strstring(char *ParentString, char *SubString) { char *pSubString, *pPareString; for(char *pTmp=ParentString; *pTmp; pTmp++) { pSubString = SubString; pPareString = pTmp; while(*pSubString == *pPareString && *pSubString != ’\0’) { pSubString++; pPareString++; } if(*pSubString == ’\0’) return pTmp; } return NULL; } int main(int argc, char* argv[]) { char *ParentString = "happy birthday to you!"; char *SubString = "birthday"; printf("%s",strstring(ParentString, SubString)); return getchar(); }}

解析
转载请注明原文地址:https://kaotiyun.com/show/vxmZ777K
0

相关试题推荐
最新回复(0)