how to copy files in c

0

How do I copy files in c?

I would like to copy the file "gg.bat" to "% AppData% \ Roaming \ Microsoft \ Windows \ Start Menu \ Programs \ Startup" as I do this using the language and tried with

so it appears:

The syntax of the file name, directory name, or volume label is incorrect.         0 file (s) copied.

    
asked by anonymous 06.04.2016 / 03:25

1 answer

0

Try this:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>

int main(int argc, char *argv[]){
    // aloca um texto para o system()
    char *command = malloc(
            strlen(argv[1])+ // tamanho da primeira string
            strlen(argv[2])+ // tamanho da segunda string
            32); // espaço extra

    sprintf(command, "cp \"%s\" \"%s\"", argv[1], argv[2]);

    system(command);

    return 1;
}

To call, simply run the executable with 2 parameters: <exe> <arquivo1> <arquivo2>

    
06.04.2016 / 03:58