1、字符串包含程序
#include<stdio.h> #include<string.h> int Strstr(char *String, char *Substring) { if(String==NULL||Substring==NULL||strlen(String)<strlen(Substring)) return -1; char *pString=String; char *pSubstring=Substring; int count=0; while(*pString!=‘\0‘) { pSubstring=Substring; while(*pSubstring==*pString) { pString++; pSubstring++; if(*pSubstring==‘\0‘) return count; } pString++; count++; } } void main() { char Str[]="ABCD"; char Substr[]="ABCDEEE"; int index=Strstr(Str,Substr); printf("%d",index); }
20140723 字符串包含程序
时间: 2024-10-07 20:57:18