【发布时间】:2016-02-03 19:20:35
【问题描述】:
我想检查 .txt 文件中是否有任何重复项。我写了一个代码,但它没有运行。我不确定在"a+" 模式下打开norep.txt 文件。想法是将我的文本的第一个单词放在norep.txt 文件中,然后将text.txt 中的每个单词与norep.txt 中的单词进行比较,然后只复制文件中我需要的单词。
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fd;
FILE *ft;
char aux[30];
char aux1[30];
int len;
fd = fopen("c:\\text.txt", "r");
if (fd == NULL) {
puts("Error");
}
ft = fopen("c:\\norep.txt", "a+");
if (ft == NULL) {
puts("Error");
}
fscanf(fd, "%s", aux);
fprintf(ft, "%s", aux);
rewind(fd);
rewind(ft);
while (!feof(fd)) {
fscanf(fd, "%s", aux);
while (!feof(ft)) {
fscanf(ft, "%s", aux1);
len = strcmp(aux, aux1);
if (len != 0) {
fprintf(ft, "%s", aux);
}
}
rewind(ft);
}
return 0;
}
【问题讨论】:
-
it's not running.为什么不呢?进一步描述您的问题。 -
程序立即结束
-
程序结束和程序未运行是很不一样的东西。
-
另外,如果遇到致命错误,请退出,不要只是打印并继续。