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
May be interested
- How to change the printer name on Windows 11when there are multiple printers on the same network, it can be difficult to identify your printer device by its default name. fortunately, windows 11 allows you to rename your printer device in several ways.
- How to rename applications in the App List in the Start menu on Windows 10the application is added to the list by proper name, for example, if you install chrome, you will see the application listed by chrome name in the app list. these names are user-friendly, but you can still rename items in the application list on the start menu if you wish.
- Instructions to rename Bluetooth devices on Windows 11on windows 11, when pairing a bluetooth device, the device appears with a default name assigned by the manufacturer. if you need to rename a bluetooth device on windows 11, follow the article below.
- Instructions for renaming display in Outlookrenaming the display in outlook email lets you set the sender's name in the right situation, or in the case of transferring the outlook work email, you need to reset the outlook display name to make it easy to contact the partner, the customer. renaming the display in outlook is not too complicated, but needs to go through a few steps. below we will show you the detailed steps to rename the sender in outlook.
- How to rename Facebook before 60 days are fastesthow to rename facebook 60 days before using cmt. official guide on how to change facebook's name when it's less than 60 days. effective way to rename faces easily.
- Instructions on how to rename Facebookinstructions on how to rename facebook. you want to change your name on facebook so your friends can easily find you on the planet's largest social network! or simply name it according to your preferences so unique and strange! this article i will guide you
- Save time with these text formatting functions in Microsoft Excelmicrosoft excel is a main application for anyone who has to work with numbers, from students to accountants. but its usefulness extends beyond a large database, it can do a lot of great things with text. the functions listed below will help you analyze, edit, convert, change text and save many hours of boring and repetitive tasks.
- How to batch rename files in Pythonbatch renaming is an effective method for organizing digital files. it can be especially useful when your filenames lack description or consistency.
- Function in programming Ca function is a group of commands that go together to perform a task. each c program has at least one function, main (), and all most normal programs define additional functions.
- DAY function in SQL Serverthe day function in sql server returns an integer that is the day of the month (from 1 to 31) from the time passed.