日期:2014-05-16  浏览次数:20652 次

linux问题
如何使用open()、read()、write()函数实现将文件file.from中的字符逐个的复制到文件file.to中?

------解决方案--------------------
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
int fd1, fd2;
int n;
char buf[100];
fd1 = open("file.from", O_RDWR);
if (fd1 < 0)
perror("open error!", errno);
fd2 = open("file.to", O_CREAT|O_RDWR);
if (fd1 < 0)
perror("open error!", errno);
while((n = read(fd1, buf, 100)))
{
write(fd2, buf, n);
}

return 0;
}

------解决方案--------------------
探讨

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
int fd1, fd2;
int n;
char buf[100];
fd1 = o……