//统计一个长度为2的字符串在另外一个字符串中出现的次数。
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int fun(char *str, char *substr)
{
char *z, *c;
z = str;
c = substr;
int n=;
while (*z!='\0')
{
if (*z== *c)
{
z++; c++;
if (*z == *c)
{
n++;
}
c--;
}
else
{
z++;
}
}
return n;
}
void main()
{
FILE *wf;
char str[],substr[];
int n;
system("CLS");
printf("输入主字符串: ");
gets(str);
printf("输入子字符串: ");
gets(substr);
puts(str);
puts(substr);
n=fun(str,substr);
printf("n=%d\n ",n);
/******************************/
wf=fopen("out.dat","w");
n=fun("asd asasdfg asd as zx67 asd mklo","as");
fprintf(wf,"%d",n);
fclose(wf);
/*****************************/
}