C语言错误在哪?
/*************found**************/
int fun(char* str, char* substr);
{
int i, j, k, num = 0;
/*************found**************/
for (i=0, str[i], i++)
for (j=i,k=0; substr[k]==str[j]; k++,j++)
/*************found**************/
If (substr[k+1] == '\0')
{
num++;
break;
}
/*************found**************/
return k;
}
main()
{
char str[80], substr[80];
printf("Input a string:");
gets(str);
printf("Input a substring:");
gets(substr);
printf("%d\n", fun(str, substr));
} 展开
已经修改完成,并运行通过:
#include <stdio.h>
/*************found**************/
int fun(char* str, char* substr) //末尾不要分号
{ int i, j, k, num = 0;
/*************found**************/
for (i=0; str[i]; i++) //中间是分号
for (j=i,k=0; substr[k]==str[j]; k++,j++)
/*************found**************/
if (substr[k+1] == '\0') //是if
{ num++;
break;
}
/*************found**************/
return num; //返回出现子串次数
}
main()
{ char str[80], substr[80];
printf("Input a string:");
gets(str);
printf("Input a substring:");
gets(substr);
printf("%d\n", fun(str, substr));
}