首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux有关问题

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

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……

热点排行