#include <stdio.h>
#include <stdlib.h>
int main() {
int c;
FILE *poem = fopen("short.txt", "r");
FILE *html = fopen("index.html", "w");
if (poem == NULL){
perror("Error in opening file");
return(-1);
}
if (html == NULL){
perror("Error in opening file");
return(-1);
}
while((c = fgetc(poem)) != EOF) {
c = getc(poem);
fputc(c, html);
}
fclose (poem);
fclose (html);
return 0;
}
我一直在寻找和尝试,但我无法弄明白。我的阅读文件只有一个单词的句子,然后当它输出到index.html
时,它们都混乱了。我真的不明白知道代码的错误。任何帮助将不胜感激。谢谢!
答案 0 :(得分:2)
您正在为每次写入执行2次读取
while((c = fgetc(poem)) != EOF) { // read
c = getc(poem); // read
fputc(c, html); // write
}