|

楼主 |
发表于 2004-8-4 11:09:14
|
显示全部楼层
我编了两个,都是一样的问题,程序和运行结果如下:
一:
int main()
{
FILE *fp1,*fp2;
char data[10];
fp1=fopen("/root/test.txt","r");
fp2=fopen("/root/copy.txt","w");
while(!feof(fp1))
putchar(getc(fp1));
rewind(fp1);
while(!feof(fp1))
putc(getc(fp1),fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
运行结果是:
[root@localhost learn]# ./kk
abcdefg
?[root@localhost learn]#
我在test.txt中的写的内容是:abcdefg
运行后copy.txt的内容是:
abcdefg
ÿ
二:
#include<stdio.h>
#include<string.h>
#include <fcntl.h>
int main()
{
int fb;
char buf[10];
if((fb = open("/root/test.txt",O_RDONLY)) == -1)
printf("open error!\n");
else
{
read(fb,buf,9);
buf[9] = 0;
printf("%s",buf);
}
close(fb);
if((fb = open("/root/copy.txt",O_WRONLY | O_CREAT)) == -1)
printf("open error!\n");
else
{
write(fb,buf,strlen(buf));
}
}
运行结果是:
[root@localhost learn]# ./kk
abcdefg
[root@localhost learn]#
运行后copy.txt的内容是:
abcdefg
运行后再打开test.txt发现它确实多了一个换行,我只对它进行了读操作,它怎么会变呢 |
|