gpt4 book ai didi

c - 我的输出文件文本与输入文本不同

转载 作者:太空宇宙 更新时间:2023-11-04 02:47:31 26 4
gpt4 key购买 nike

#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时全乱了。我真的不明白代码有什么问题。任何帮助将不胜感激。谢谢!

最佳答案

每次写入都需要读取 2 次

  while((c = fgetc(poem)) != EOF) {  // read
c = getc(poem); // read
fputc(c, html); // write
}

关于c - 我的输出文件文本与输入文本不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25704551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com