codescracker


c

C rename()



« Previous Function Next Function »


rename()

The rename() function changes the name of the file specified by oldfname (old file name) to newfname (new file name). The newfname must not match with any existing file name present in the current directory

rename() Syntax

#include<stdio.h>
int rename(const char *oldfname, const char *newfname);

The rename() returns zero if successful, otherwise returns non-zero if an error has occurred.

rename() Example

Following c program ask to the user to enter the two file name to change the name of the first file with the second file name:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
	clrscr();
	char firstfile[20], secondfile[20];
	printf("Enter first file name : ");
	gets(firstfile);
	printf("Enter second file name : ");
	gets(secondfile):
	if(rename(firstfile, secondfile) != 0)
	{
		printf("Error occurred in renaming the file..!!\n");
		printf("Press any key to exit..\n");
		getch();
		exit(1);
	}
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test