求教。。。一道简单的问题。。
喵咪_ 2014-10-23 11:48:50 题目是编写函数统计子字符串在另一个字符串中出现的次数,字符串和子字符串都由键盘输入。例如,假定输入的字符串为“asd asasdfg as zx67 asd mklo”,子字符串为“as”,函数返回值为5.
然后我写的程序如下。。运行以后就是输入了数据但是无返回结果。。。求大神帮助
#include<stdio.h>
#include<stdlib.h>
int main()
{
char str_1[99],str_2[99];
int j,i=0,m=0;
puts("姓名:刘晟玮,学号:104052012013");
puts("请输入字符串:");
gets(str_1);
puts("请输入要查询的子串:");
gets(str_2);
while(str_1[i]!='\0')
{
j=0;
while(str_2[j]!='\0')
{
if (str_1[i]==str_2[j])
{
j++;
i++;
}
else
break;
if (str_2[j]='\0')
m++;
i++;
}
}
printf("%d\n",m);
system("pause");
}