用C语言实现类似“cp file1 file2”命令

来源:互联网 发布:知乎机构号注册 编辑:程序博客网 时间:2024/05/17 12:46
#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#define MaxBytes 1024int main(int argc, char * argv[]){int in, out;int need;char buffer[MaxBytes + 1];if (argc < 3){printf("please input source file path and destination file path\n");exit(1);}in=open(argv[1],O_RDONLY);out=open(argv[2], O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);while ((need = read(in, buffer, MaxBytes)) > 0){write(out, buffer, need);}exit(0);}

0 0
原创粉丝点击