文件copy命令的源代码

文件copy命令的源代码

/*
  Name: x_copy.c
  Author: x-bit at 167168.kmip.net(纯技术论坛)
  Description: 文件copy命令,只能copy 一个文件。
               用法:命令 源文件 目标文件
               dev-cpp5 + win2k下调试通过;
               转载请保留文章的完整性.
  Date: 08-11-2004
  Copyright: x-bit(三哥) Allrights Reserved.
*/

#include <stdio.h>
void usage(char *msg)
{
    puts(msg);
    puts("usage: command source target");
    exit(0);
}
void errMsg(char *msg)
{
    puts("File operation failure.");
    puts(msg);
    exit(0);
}
int main(int argc, char *argv[])
{
    FILE *si, *di;
    if(argc==1)
    {
        usage("parameter error");
    }
    else if(argc==2)
    {
        if(si=fopen(argv[1], "rb"))
            usage("Unable copy to itself./ncopy 0 file.");
        else
            usage("can't open the file");
    }
    else if(argc>3)
    {
        usage("parameter error");
    }
   
    if(!(si=fopen(argv[1], "rb")))
        errMsg("can't open the file");
    if(!(di=fopen(argv[2], "wb")))
        errMsg("can't creat the file");
    while(!feof(si))
        fputc(fgetc(si), di);
       
    fclose(si);
    fclose(di);
    puts("copyed 1 file.");   
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值