易截截图软件、单文件、免安装、纯绿色、仅160KB

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

即实现简单的copy功能
要求:只用 open()  read() write() 和close()系统调用.


cat file1 >> file2 ?

open()连个文件,read()其中一个内容,write()到另外一个文件上,最后close()掉。

能不能用lseek函数?


C/C++ code:

#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);
}




不好意思,少copy半边“}”

引用
不好意思,少copy半边“}”

非常好


相关问答:

linux环境下gethostbyname函数问题 - C/C++ / C语言

写了个测试程序如下
   
  struct hostent *hp; 
char AlarmDevIP[20];  
  int x2;

hp = gethostbyname("www.google.com");
if (hp)
{ ......

使用Struts2上传文件,在linux下报错

使用Struts2上传文件,在linux下报错
2009-09-29 14:56:20,801 [org.apache.struts2.interceptor.FileUploadInterceptor]-[ERROR] Processing of multipart/form-data request failed. c:/temp/upload__1dcd07ee_12 ......

在 LINUX系统中的ORACLE怎么新建表空间?

请教:
在 LINUX系统中的ORACLE怎么新建表空间?
一样的命令啊。如果没用omf的话,你就指定下路径和数据文件名就行了。
create tablespace xxx datafile '/u01/..../aaa.dbf' size 10m;

CREATE TA ......

关于linux下socket编程的问题! - C/C++ / C语言

由于我才刚刚接触socket编程,自己写了一个简单程序,但就是在运行的时候出现段错误,无法解决,现在我把源代码贴出来,请各位大虾指正一下!谢谢!
#include<stdio.h>
#include<stdlib.h>
#include& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号