美文网首页
open-read-write--copy.c

open-read-write--copy.c

作者: 半步江南 | 来源:发表于2018-12-22 22:32 被阅读10次

    include <unistd.h>

    include <sys/stat.h>

    include <stdlib.h>

    include <fcntl.h>

    include <stdio.h>

    int main(){

    char buffer[11];
    int nread=1,nwrite=0;
    int in,out;
    //char * path;
    //int i,flag;
    char path1[]="/root/study-dir/linux_program_design/chapter_3/read.c";
    char path2[]="/root/study-dir/linux_program_design/chapter_3/test.out";
    in = open(path1,O_RDONLY);
    out = open(path2,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
    while(nread!=0)
    {
    nread=read(in,buffer,11);
    nwrite=write(out,buffer,nread);
    }
    exit(0);
    }

    相关文章

      网友评论

          本文标题:open-read-write--copy.c

          本文链接:https://www.haomeiwen.com/subject/synwkqtx.html