#include
#include
int main()
{
char f[128],key[64],buf[1024],*pos;
int count=0;
FILE *inf;
printf("请输入要在其中查找关键词的文件名和关键词:");
scanf("%s %s",&f,&key);
inf=fopen(f,"r");
while(fgets(buf,1024,inf))
{
pos=buf;
while(pos=strstr(pos,key))
{
count++;
pos=pos+strlen(key);
}
}
printf("关键词%s在文件%s中共出现了%d次。\n",key,f,count);
fclose(inf);
system("PAUSE");
return EXIT_SUCCESS;
}
20rmb帮写 私信