一个蛮有趣的问题,大家一起解决下啊!!!!!!!!!!!!
#include<stdio.h>#include<stdlib.h>
#include<string.h>
int main() {
FILE *fp1;
char ch, file1[50], a[15];
int n = 0, nlong, i = 0;
printf("输入你要查找的单词\n");
scanf("%s", a);
nlong = strlen(a);
printf("\n请输入文件路径及文件名\n");//c:\computer\readme.txt 这样输入错误的 因为\转义只有输入 c:\\computer\\readme.txt 那如果
scanf("%s", file1); //要输入c:\computer\readme.txt 该怎么改呢?
if ((fp1 = fopen(file1, "r")) == NULL) {
printf("打开失败");
exit(0);
}
ch = fgetc(fp1);
while (!feof(fp1)) {
i = 0;
while (i < nlong) {
for (; ch == a[i]; ch = fgetc(fp1))
i++;
if (i == nlong)
n++;
if (ch == a[0])
break;
if (ch != a[0]) {
ch = fgetc(fp1);
break;
}
}
}
printf("%d", n);
fclose(fp1);
return 0;
}