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.
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
Difference between function and formula in Excel
8 little-known Excel functions that can save you a lot of work
How to use the NORMDIST function in Excel - Function that returns the distribution in Excel
Date functions in Excel, DAY, WEEKDAY, MONTH
How to use the SUMIF function in Excel to calculate the sum based on conditions
How to use the Round function in Excel to round numbers and process data