rename() and remove() in C

Previous
Next

rename():

  • It used to rename the specified file.
  • Prototype is:
    • int  rename(char* old, char* new);
    • On success, it returns 0
    • On failure, it returns -1
#include<stdio.h>
int main()
{
	char old[20] = "data.txt";
	char new[20] = "modified_data.txt";
	
	if(rename(old, new)==0)
		printf("successfully renamed...\n");
	else
		printf("Failed in renaming the file...\n");
	return 0;
}

remove():

  • It used to rename the specified file.
  • Prototype is:
    • int  remove(char* target);
    • On success, it returns 0
    • On failure, it returns -1
#include<stdio.h>
int main()
{
	char target[20] = "data.txt";
	
	if(remove(target)==0)
		printf("successfully removed...\n");
	else
		printf("Failed in removing the file...\n");
	return 0;
}
Previous
Next

Add Comment

Courses Enquiry Form