p5.4.c

来自「linux程序设计例程」· C语言 代码 · 共 42 行

C
42
字号
#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>int main(int argc,char* argv[]){	int fd1,fd2;	char buffer[100];	int num;	if(argc!=3){		printf("Usage : %s source dest",argv[0]);		return 1;	}	if((fd1=open(argv[1],O_RDONLY))==-1){		perror("Cannot open the file");		return 1;	}	if((fd2=open(argv[2],O_CREAT | O_WRONLY,0777))==-1){		perror("Cannot create the destination file");		return 1;	}	        while((num=read(fd1,buffer,100))>0){				if(write(fd2,buffer,num)==-1){			perror("Cannot write the file content to the file");			return 1;		}	}		close(fd1);	close(fd2);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?