一、思路
二、实现代码
#include<stdio.h>
int main(int agrc,char **argv)
{
printf("total params:%d\n",agrc);
printf("NO.1 param:%s\n",argv[0]);
printf("NO.2 param:%s\n",argv[1]);
printf("NO.3 param:%s\n",argv[2]);
return 0;
}
~
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
int main(int argc,char **argv)
{
int fdSrc,fdDes;
char *readbuf = NULL;
if(argc != 3){
printf("param error\n");
exit(-1);
}
fdSrc = open(argv[1],O_RDWR);
int size = lseek(fdSrc,0,SEEK_END);
lseek(fdSrc,0,SEEK_SET);
readbuf = (char *)malloc(sizeof(char)*size + 8);
int n_read = read(fdSrc,readbuf,size);
fdDes = open(argv[2],O_RDWR|O_CREAT,0600);
write(fdDes,readbuf,strlen(readbuf));
close(fdSrc);
close(fdDes);
return 0;
}
输出结果: