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

2024-12-24 22:14:40
推荐回答(2个)
回答1:

#include #include /* 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;}

回答2:

如果输入str1为"aaaaa",str2为"aaa",那么调用函数StrCount后函数的返回值应该为多少?