看板 C_and_CPP 關於我們 聯絡資訊
開發平台(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
noodleT: http://ideone.com/EAC3wI 09/20 23:01
noodleT: 看起來是 r+ 的問題 09/20 23:01
LPH66: 關於開檔模式參見 #1BAx0W_v 09/20 23:56