【无标题】

1.

2.

3.#include <stdio.h>//标准IO的头文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

int main(int argc,char **argv)
{
    //argc存的是参数的个数
    
    
    printf("argc=%d\n",argc);
    
    if(argc != 4)
    {
        printf("你个傻逼,我只要两个参数\n");
        return -1;
    }
    //argv存的是参数的字符串形式
    //argv[0] ./a.out
    //argv[1]  1.txt
     //argv[2]  2.txt
    //argv[3]  3.txt
    
    //把第一个参数复制到第二个参数
    
    
    int fd1 = open(argv[2], O_RDWR);//如果参数里出现了O_CREAT,
                                            //那就需要多填一个mode_t类型的文件权限
    if(-1 == fd2)
    {
        printf("打开%s失败,错误为%s\n",argv[2],strerror(errno));
    }

    
    int fd2 = open(argv[3], O_RDWR | O_CREAT,0777);
    if(-1 == fd2)
    {
        printf("打开%s失败,错误为%s\n",argv[2],strerror(errno));
    }
    
    
    char buf[100];
    while(1)
    {
        memset(buf,0,100);
        int ret = read(fd2,buf,sizeof(buf)-1);
        
        write(fd3,buf,strlen(buf));
        
        if(0 == ret)
        {
            break;
        }
        
    }
        
    close(fd2);
    close(fd3);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值