Pointer to a null-terminated string containing the name of the file or directory to be renamed.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
Pointer to a null-terminated string containing the new name for the file or directory.
Read more about parameters of rename in parameters section
The renamefunction in C language Renames a file or directory.
The rename function changes the name of a file or directory. It can also be used to move a file between directories on the same file system. If a file with the new name already exists, it may be overwritten depending on the system and implementation.
The renamefunction takes 2
parameters:
•
const char * `oldname`: Pointer to a null-terminated string containing the name of the file or directory to be renamed.
•
const char * `newname`: Pointer to a null-terminated string containing the new name for the file or directory.
Renames the file or directory specified by `oldname` to `newname`. If `newname` already exists, its behavior is implementation-defined, but it may overwrite the existing file or directory. Returns `0` on success or a nonzero value on failure, with `errno` set to indicate the error.
The rename function return value :
Returns 0 if the file was successfully renamed, non-zero if an error occurred
Output
This example creates a file, closes it, and then renames it using the rename function.