写出在母串中查找子串出现次数的代码
#include<stdio.h>
int count1(char* s1, char* s2)
{
int count = 0;
while(*s1!=‘\0‘)
{
while(*s2 == *s1&&(*s2!=‘\0‘)&&(*s1!=‘\0‘))
{
s2++;
s1++;
}
if(*s2 == ‘\0‘)
count++;
s1++;
}
return count;
}
main()
{
char* s1="zhousenshan";
char* s2="o";
printf("%d",count1(s1, s2));
}
原文地址:http://www.cnblogs.com/zhouxiansheng/p/3965110.html