linux ,编写一个程序,把一个文件复制到另一个文件上

sekingna 2009-12-02 11:57:14
即实现简单的copy功能
要求:只用 open() read() write() 和close()系统调用.

...全文
1138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Caballeroo 2009-12-02
  • 打赏
  • 举报
回复
open()连个文件,read()其中一个内容,write()到另外一个文件上,最后close()掉。
superbtl 2009-12-02
  • 打赏
  • 举报
回复
cat file1 >> file2 ?
xiaoyuanwang 2009-12-02
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jerry_gao_jie 的回复:]
不好意思,少copy半边“}”
[/Quote]
非常好
jerry_gao_jie 2009-12-02
  • 打赏
  • 举报
回复
不好意思,少copy半边“}”
jerry_gao_jie 2009-12-02
  • 打赏
  • 举报
回复 2

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

#define BUF_SIZE 1024*8
int main()
{
int fds, fdd;
char buf[BUF_SIZE];
size_t hasread = 0;
fds = open("filea", O_RDONLY);
fdd = open("fileb", O_WRONLY, O_CREAT);
if(fds && fdd)
{
while((hasread = read(fds, buf, sizeof(buf))) > 0)
{
write(fdd, buf, hasread);
}
close(fds);
close(fdd);
}

YonRui 2009-12-02
  • 打赏
  • 举报
回复
能不能用lseek函数?

23,116

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧