[问题] 两个文件档内容合并然后显示在萤幕

楼主: ninefboomer (青春的回忆)   2016-09-20 20:31:16
开发平台(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
作者: noodleT (面T)   2016-09-20 23:01:00
http://ideone.com/EAC3wI看起来是 r+ 的问题
作者: LPH66 (-6.2598534e+18f)   2016-09-20 23:56:00
关于开档模式参见 #1BAx0W_v

Links booklink

Contact Us: admin [ a t ] ucptt.com