问题
I need to move a file from an input to a certain folder, however, 'rename' keeps crashing the entire application.
char start[50];
const char dest = "C:\Windows\System32\oobe\info\backgrounds\supertemp.JPG";
printf("Please enter file to move \n");
fgets(start, sizeof(start), stdin);
if (rename(start, dest) == 0){
printf("Success \n");
}
else{
printf("Failed %s ", GetLastError());
}
It always crashes at ' if(rename(start, dest) ==0)'.
I don't ever get as far as retrieving an error value.
Any help would be greatly appreciated! Cheers
回答1:
Two problems. You have not declared dest
as an array, and you need to put a double \\ in a literal string, to prevent \ being used as an escape character.
const char dest[] = "C:\\Windows\\System32\\oobe\\info\\backgrounds\\supertemp.JPG";
来源:https://stackoverflow.com/questions/26577984/how-to-move-a-file-in-c