求答案 c语言编程:编写函数int StrCount(char* str1,char* str2)。

编写函数int StrCount(char* str1,char* str2)。Str1和str2为两个输入的字符串。函数统计str2在str1中出现的次数,返回该数值。要求:在主函数main中初始化str1和str2,调用函数StrCount(str1,str2)后输出结果。如输入str1为"howareyouareGGGare",str2为"are",那么调用函数StrCount后函数返回3

#include <stdio.h>#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int StrCount(char* str1,char* str2){ int i,j; int count=0; i=j=0; while(str1[i]!='\0') { while(str1[i]!='\0'&&str2[j]!='\0') { if(str1[i]==str2[j]) { i++; j++; } else { i=i-j+1; j=0; } } if(str2[j]=='\0') { count++; j=0; } } return count;} int main(int argc, char *argv[]) { int count; char str1[]="howareyouareGGGare"; char str2[]="are"; count=StrCount(str1,str2); printf("%d",count); return 0;}
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-01-03
如果输入str1为"aaaaa",str2为"aaa",那么调用函数StrCount后函数的返回值应该为多少?
相似回答