Board logo

标题: 如何用TC写一个DOS下文件拷贝的程序啊? [打印本页]

作者: cicada     时间: 2004-5-30 00:00    标题: 如何用TC写一个DOS下文件拷贝的程序啊?

在DOS下如何用TC写不同分区的文件拷贝的程序啊?用到哪些函数呢?帮帮忙啊!
作者: bush     时间: 2004-5-30 00:00
要取不同分区,要用以下函数,当然写copy函数可以用两个参数来完成,应该不难。
getdisk: gets current drive

int getdisk(void);

Prototype in dir.h

Returns the current drive. Drive A is 0.

setdisk: sets current disk drive

int setdisk(int drive);

Prototype in dir.h

Values for drive are 0=A, 1=B, 2=C etc.

Returns the total number of drives available.


作者: cicada     时间: 2004-5-31 00:00
"当然写copy函数可以用两个参数来完成" 哪两个参数呢?如何确定制定文件的目录呢?有没有类似的源代码啊?谢谢了!
作者: bush     时间: 2004-5-31 00:00
刚才我写了一个,最少地调用函数,你可以参考一下:
/*filename: mycopy.c    a example for copy a file to another file*/
#include
int main(int argc,char* argv[])
{
FILE *fpo,*fpi;
int tmp;
char *fname;
if(argc==1)
            {
            printf("Syntax is mycopy sourcefile targetfile\n";
            exit (1);
            }
fpi=fopen(argv[1],"rb";
if(!fpi)
         {
         printf("cannot open the sourcefile!\n";
         exit (2);
         }
if(argc==2)
            {
            printf("Please input target file name:";
            while(scanf("%s",&fname));
            fpo=fopen(fname,"wb";
            }
else fpo=fopen(argv[2],"wb";
if(!fpo)
         {
         printf("cannot creat the targetfile!\n";
         exit (3);
         }
while((tmp=fgetc(fpi))!=EOF)
                      fputc(tmp,fpo);
fclose(fpi);
fclose(fpo);
return 0;
}


作者: cicada     时间: 2004-6-1 00:00
谢谢了。




欢迎光临 中国DOS联盟论坛 (http://cndos.fam.cx/forum/) Powered by Discuz! 2.5