/*
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;
}