一、分屏查看打开两文件命令
vimdiff demo1.c demo2.c
:qall(退出)
二、打印下参数的总个数和各参数值
1 #include<stdio.h>
2 #include<stdlib.h>
3
4 int main(int argc,char **argv)
5 {
6 if(argc!=3){
7 printf("param error\n");
8 exit(-1);
9 }
10 printf("totall num of param is =%d\n",argc);
11 printf("num 1 param is %s\n",argv[0]);
12 printf("num 2 param is %s\n",argv[1]);
13 printf("num 3 param is %s\n",argv[2]);
14
15 return 0;
16 }
三、cp代码实现
1 #include<stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include<stdlib.h>
5
6 int main(int argc,char **argv)
7 {
8 if(argc!=3){
9 printf("param error\n");
10 exit(-1);
11 }
12 printf("totall num of param is =%d\n",argc);
13 printf("num 1 param is %s\n",argv[0]);
14 printf("num 2 param is %s\n",argv[1]);
15 printf("num 3 param is %s\n",argv[2]);
16
17 int fdsrc;
18 fdsrc = open(argv[1],O_RDWR);
19
20 int size;
21 size=lseek(fdsrc,0,SEEK_END);
22 lseek(fdsrc,0,SEEK_SET);
23
24 char *buf=NULL;
25 buf = (char*)malloc(sizeof(char)*size+1);
26 int n_read = read(fdsrc,buf,size);
27
28 int fddes;
29 fddes = open(argv[2],O_CREAT|O_TRUNC|O_RDWR);
30 int n_write = write(fddes,buf,size);
31
32 printf("read %d byte to buf\n,write %d byte to fddes file\n",n_read,n_write);
33
34 return 0;
35 }