问题 N: 程序填充(函数、指针):findthe

下面程序中"____ N ____"是根据程序功能需要填充部分,请完成程序填充(注意:不得加行、减行、加句、减句,否则后果自负)。 该程序功能:调用find函数在输入的字符串中查找是否出现"the"这个单词。如果查到返回出现的次数;如果未找到返回0。 #include "stdio.h" int find(char *str) { char *fstr="the"; int i=0,j,n=0; while (str[i]!='\0') { for(1) if (str[j+i]!=fstr[j]) break; if (2) n++; i++; } return n; } void main() { char a[80]; gets(a); printf("%d",find(a)); }
输入
输入一个任意字符串(少于80个字符)。
输出
输出“the”出现的次数。
样例输入 Copy
the book on the table is mine.
样例输出 Copy
2

#include "stdio.h"

int find(char *str) {
char *fstr = "the";
int i = 0, j, n = 0;
while (str[i] != '\0') {
for (j = 0; j < 3; j++)
if (str[j + i] != fstr[j])
break;
if (j == 3)
n++;
i++;
}
return n;
}

int main() {
char a[80];
gets(a);
printf("%d", find(a));
}

#include <stdio.h>

int find(const char *str)
{
    const char *fstr = "the";
    int i = 0, j, n = 0;
    while (str[i] != '\0')
    {
        for (j = 0; j < 3; j++)
            if (str[j + i] != fstr[j])
                break;
        if (j == 3)
            n++;
        i++;
    }
    return n;
}

int main()
{
    char a[80];
    fgets(a, 80, stdin);
    printf("%d", find(a));
}