2014-09-06 38 views
1
#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

混乱了,或每第二个字符? – 2014-09-06 20:45:30

回答

2

你正在做2读取每个写

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

谢谢。这解决了它。 – Rugaloo 2014-09-06 20:44:45

+1

呵呵,**你**修好后我指出错误:) – pmg 2014-09-06 20:46:09

+0

没有你的评论修正了它。 “那”在你的答案中。 – Rugaloo 2014-09-06 20:47:41