2014-09-06 134 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