帮朋友做的一道题目,计算一行英文作文里某个特定的单词出现的次数,【ps那篇英文作文我以附件的形式上传上来了】要求:需要搜索的几个单词在一次输入后的到其出现次数,作文也只是一行的英文。这个程序写完没语法错误,但却无法运行,我c学得渣渣的,搞了很久都不知道到底应该怎么改进。但我肯定应该是程序最后几行中的
“for(m=0;m<=2;m++){ getsentence(str1,fp,str2[m]);
printf("The word %s which you want to search in the file have been appeared %d times in total!\n",str2[m],sum);}”
出现了 错误,但又不知道应该怎么改,跪求好心人搭救orz。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define N 200
#define M 20
static int sum=0; /*sum是用来记录目标单词总共出现的次数,必须用static型*/
/*******************************************************************/
int main()
{
char str1[M];
char str2[2][M];
char filename[M];
int m;
FILE* fp;
printf("Please input the name of the file:\n");
scanf("%s",filename);
printf("\n");
printf("Please input the word which you want to search:\n");
scanf("%s %s %s",str2[0],str2[1],str2[2]);
fp=fopen(filename,"r");
if(fp==NULL){
printf("cannot open the file\n");
exit(0);
}
for(m=0;m<=2;m++)
{ getsentence(str1,fp,str2[m]);
printf("The word %s which you want to search in the file have been appeared %d times in total!\n",str2[m],sum);}
fclose(fp);
system("pause");
return 0;
}