文件复制

#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include  <fcntl.h>
int main()
{
    char c;
    int in,out;
   in=open("file.in",O_RDONLY);
   out=open("file.out",O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
   while(read(in,&c,1)==1)
       write(out,&c,1);
   exit(0);
}
//速度1kB
int main()
{
    char c[1024];
    int in,out;
    int nread;
   in=open("file.in",O_RDONLY);
   out=open("file.out",O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
   while((nread=read(in,c,sizeof(c)))>0)
       write(out,c,nread);
   exit(0);
}


posted @ 2015-09-22 16:07  陈泉宏  阅读(205)  评论(0编辑  收藏  举报