-2
I have a file called Tempfile.txt I made the following script in c to rename file receiving the file name to be renamed and the new name, but it is returning this error:
Error renaming file: Bad address Output new name:
The script is this below:
#include <stdio.h>
int main()
{
 char *oldname;
 char *newname;
 printf("\n\tInput name file: ");
 scanf("%s", oldname);
 printf("\n\tOutput new name: ");
 scanf("%s", newname);
 if(rename(oldname, newname) == 0)
  puts("File successfully renamed");
 else
  perror("Error renaming file");
 return 0;
}
Whenever you publish a question or answer format the code with
Ctrl-kor use the button{}of the editor– Isac