编译结果总是蛋的情况,求分析。
//在字符串str中找字符串substr出现的次数#include<iostream>
#include<cstring>
using namespace std;
void SubStrNum(char *str,char *substr);
int main()
{
char str1[1000];
char substr[] = {'s','u','b','s','t','r','\0'};
cin>>str1;
SubStrNum(str1,substr);
return 0;
}
void SubStrNum(char *str,char *substr)
{
int m = 0;
char *sp = str;
while(*sp != '\0')
{
char *rp = substr;
int k = 0;
while(*sp == *rp && k<6)
{
sp++;
rp++;
k++;
}
if(k == 5)
m++;
}
cout<<m<<endl;
}