Linux下C语言复制文件

从usr/bin/info复制到myinfo.c

#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
int main()
{
    const char* pathName="myinfo.c";
    int in,out,flag;
    char buffer[10240];
    in=open("//usr//bin//info",O_RDONLY,S_IRUSR);
    if(in==-1)
    {
        printf(" 打开文件info失败 !\n");
        return -1;
    }
    out=creat(pathName,S_IWUSR);
    if(in==-1)
    {
        printf("创建文件myinfo失败!\n");
        return -1;
    }
    while((flag=read(in,buffer,10240))>0)
    {
        write(out,buffer,flag);
    }
    close(in);
    close(out);
    printf("复制文件info到myinfo完成!\n");
    return 0;
}

 

posted @ 2019-09-19 19:36  MMinoz  阅读(2019)  评论(0编辑  收藏  举报