错误在哪里
#include <string.h> /*此程序用来计算一短字符串在长字符串中出现的次数。*/main()
{
int i;
char s1[100],s2[100];
printf("Please input a long string:");
scanf("%s",s1);
printf("Please input a short string:");
scanf("%s",s2);
i=compare(s1,s2);
printf("The short string appeared %d times.\n", i);
getch();
}
compare(char str1[],char str2[])
{
int couter=0;
int i,j,n1,n2;
n1=strlen(str1);
n2=strlen(str2);
for (i=0;i<=n1-n2;i++)
for (j=0;j<n2;j++)
{
if (str2[j]==str1[i+j])
{
if (j==n2-1)
couter++;
else
j++;
}
else
break;
}
return(couter);
}
为什么输出结果不对