[問題] 兩個文件檔內容合併然後顯示在螢幕

看板C_and_CPP作者 (青春的回憶)時間7年前 (2016/09/20 20:31), 編輯推噓2(201)
留言3則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Xcode: C 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 兩個文件檔內容合併再輸出到螢幕上 餵入的資料(Input): 兩個文件檔 try: abcde try1: fghij 預期的正確結果(Expected Output): abcdefghij 錯誤結果(Wrong Output): 只顯示e 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <stdlib.h> int main() { FILE *fptr, *fptr1; char str[ 7] ; fptr1 = fopen("/Users/huyentung/Desktop/test/test1/test1/try1.txt", "r+"); if ((fptr = fopen("/Users/huyentung/Desktop/test/test1/test1/try.txt", "r")) == NULL) puts("unable to open"); else while (fgets(str, 7, fptr) != NULL) { fputs(str, fptr1); } fclose(fptr1); fclose(fptr); if ((fptr1= fopen("/Users/huyentung/Desktop/test/test1/test1/try1.txt", "r")) == NULL) puts("unable to open"); else while (fgets(str, 7, fptr1) != NULL) printf("%s\n", str); fclose(fptr1); return 0; } 補充說明(Supplement): 剛學C一個月,請鞭小力點QQ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.163.97 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1474374678.A.247.html

09/20 23:01, , 1F

09/20 23:01, , 2F
看起來是 r+ 的問題
09/20 23:01, 2F

09/20 23:56, , 3F
關於開檔模式參見 #1BAx0W_v
09/20 23:56, 3F
文章代碼(AID): #1NuImM97 (C_and_CPP)