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