从一个驱动器转移到另一个驱动器的C代码 [英] C code for transferring from one drive to another

查看:108
本文介绍了从一个驱动器转移到另一个驱动器的C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想要一个C代码,用于将一个文件从一个驱动器位置传输到另一个驱动器中的另一个文件.输出将类似于要求用户在第一个驱动器中提供文件的路径,然后找到该文件,然后再次询问要传输的路径(目的地).....

Hey guys,

I want a C code for transferring one file from one drive location to another file locating in another drive. The output will be like the user will be asked for path of the file in the first drive,then locate it and then again asked for the path to transfer(destination).....

推荐答案

Google [
Is Google[^] so hard to use?

Look, that''s the first link itself.


FILE *fs,*ft;
    char ch;
    char strSource[_MAX_PATH];
    char strDestination[_MAX_PATH];
    printf("\n Enter the source file path  :  ");
    scanf("%s",&strSource);
    // Open source file in Read mode
    fs = fopen(strSource,"r");
    if(fs==NULL)
    {
        printf("\n Cannot open source file !");
        return 1;
    }
    printf("\n Enter the source file path  :  ");
    scanf("%s",&strDestination);
    // Open destination file in Write mode
    ft = fopen(strDestination,"w");
    if(ft==NULL)
    {
        printf("\n Cannot copy file ! ");
        fclose(fs);
        return 1;
    }
    while(true)
    {
        ch = getc(fs);
        if(ch==EOF)
            break;
        else
            putc(ch,ft);
    }
    printf("\n File copied succesfully!");
    fclose(fs);
    fclose(ft);
    return 0;


这篇关于从一个驱动器转移到另一个驱动器的C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆