copy a file from one directory to another in c

Change this:

system("cp source destination");

To this:

std::string cmd = std::string("cp '") + source + "' '" + destination + "'";
system(cmd.c_str());

And BTW, you should either return from inside the if(argc != 3) statement, or do the rest of the code inside an else statement.

Lastly, function int main(int argc, char *argv[]) requires that you return an int value.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top