Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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).....
Posted
Updated 8-Feb-11 22:05pm
v2

Is Google[^] so hard to use?

Look, that's the first link itself.
 
Share this answer
 
C#
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;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900