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

admin2019-03-29  75

问题 实现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://jikaoti.com/ti/9ag7FFFM
0

最新回复(0)