下面的函数统计子字符串substr在字符串str中出现的次数,如果substr在str中不出现,则返回值0。请完成该函数。
int str_count(char *substr, char *str)
{
}
下面的函数统计子字符串substr在字符串str中出现的次数,如果substr在str中不出现,则返回值0。请完成该函数。
int str_count(char *substr, char *str)
{
}
int count=0;
char *pChar;
if(substr==NULL||str==NULL) return count;
while(*str!='\0'){
pChar=substr;
while(*pChar==*str){
pChar++;
if(*pChar=='\0'){
count++;break;
}
else
str++;
}//Match while(*pCh...) statement
str++;
}//Match
while(*str...) statement
return count;