If the program needs to rename a file (to create a backup, for example, before writing the new file), it can be done with a simple call to the rename function from stdio.h:
int rename ( const char * old_name, const char * new_name )
If a file with the new_name already exists, the return value will be an error. To check in advance, the program simply needs to call the fopen function with the r flag set. The same applies to the file referred to with the old_name parameter.
You can delete a file by calling the remove function:
int remove ( const char * filename )
Some compilers also provide an unlink function, which performs the same file deletion. File deletion will take place if the file exists and if it’s empty. Some ...