/////////////////////////////////////////////mycopy.cpp存放在D盘下D:\mycopy.cpp(或是其它路径).
////////程序启动时的"命令行参数"与调用main()的"函数实参"不同.
////////命令行参数是由启动程序截获并找包成字符串数组后传递给main()的一个形参argValue的.
///////而包括命令字(即可执行文件名称)在内的所有参数的个数则被传递给形参argCount.
//mycopy.cpp
#include<stdio.h>
#include<iostream.h>
int main(int argCount, char* argValue[])
{
FILE *srcFile = 0,*destFile=0;
int ch = 0;
if(argCount != 3)
{
cout<<argValue[0]<<endl;
printf("Usage:%s src-file-name dest-file-name\n", argValue[0]);
}
else
{
if( (srcFile = fopen(argValue[1], "r")) == 0)
{
printf("can not open source file\"%s\" !",argValue[1]);
}
else
{
if((destFile = fopen(argValue[2], "w")) == 0)
{
printf("can not open destination file\"%s\"!",argValue[2]);
fclose(srcFile);
}
else
{
while((ch = fgetc(srcFile)) != EOF )
fputc(ch, destFile);
printf("successful to copy a file!\n");
fclose(srcFile);
fclose(destFile);
return 0;
}
}
}
return 1;
}
/////////////////////////////////////////////
然后DOS下切换到mycopy.cpp存放的盘符下,现我存放在D盘下
c:\Documents and Settings\Administrator>d:
D:\>CL mycopy.cpp 注释:编译mycopy.cpp , 产生mycopy.obj中间代码文件
D:\>LINK mycopy.obj 注释:连接mycopy.obj文件,生成mycopy.ext文件
D:\>mycopy d:\file2.txt d:\myfile1.txt 注释:把file2.txt中的内容制到file1.txt文件中去