其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
文件copy命令的源代码

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

文件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;
}




相关文章

相关软件