本帖最后由 jiangenhao 于 2014-4-26 01:03 编辑
- 下面程序的功能是统计字串sub在母串s中出现的次数。请填空
- #include "stdio.h"
- #include "string.h"
- main()
- {
- char s[80], sub[80];
- int n;
- gets(s);
- gets(sub);
- printf("%d\n", count(s,sub));
- }
- int count( char *p, char *q)
- {
- int m, n, k, num=0;
- for (m=0; p[m]; m++)
- for (【1】, k=0; q[k]==p[n]; k++, n++)
- if(q[【2】]=='\0')
- { num++; break;}
- return (num);
- }
复制代码 |