Rename () function in C
The function int rename (const char * old_filename, const char * new_filename) in Library C standard makes filename referenced, changed from old_filename to new_filename.
The function int rename (const char * old_filename, const char * new_filename) in Library C standard makes filename referenced, changed from old_filename to new_filename.
Declare rename () function in C
Below is the declaration for rename () function in C:
int rename ( const char * old_filename , const char * new_filename )
Parameters
old_filename - This is the string containing the file name to be renamed and / or moved.
new_filename - This is the string containing the new name for the file.
Returns the value
If successful, the function returns 0. If there is an error, the function returns -1 and errno is set appropriately.
For example
The following program C illustrates how to use the rename () function in C:
#include int main () { int ret ; char oldname [] = "baitapc.txt" ; char newname [] = "baitapc1.txt" ; ret = rename ( oldname , newname ); if ( ret == 0 ) { printf ( "Doi ten file thanh cong !!!" ); } else { printf ( "Error: khong the doi ten file" ); } return ( 0 ); }
Suppose we have baitapc.txt with some content. We are preparing to delete this file by using the above program. Compile and run the above program to create the following message and the file will be renamed to baitapc1.txt.
According to Tutorialspoint
Previous post: remove () function in C
Next lesson: The rewind () function in C
You should read it
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? The most beautiful meteor shower of the year and amazing astronomical phenomena in August Is Proxima b our 'neighbor' planet? Why have scientists found Proxima b - '2nd Earth' until now? The mystery of the numbers of Proxima b: The 'Second Earth' on the planet may exist life Early in the morning, Venus and Jupiter will meet in the sky, don't miss this magical, rare moment!