開發平台(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