Thursday

Write a program to rename and delete a data file using rename and remove command.

#include<stdio.h>
#include<conio.h>
void main()
{
char filename[20];
char oldfilename[20],newfilename[20];
printf("\n Enter the file name to be removed: ");
gets(filename);
if(remove(filename)==0)
printf("File %s is removed",filename);
else
printf("File %s cannot be removed",filename);
printf("\n Enter old file name: ");
gets(oldfilename);
printf("\n Enter new file name: ");
gets(newfilename);
if(rename(oldfilename,newfilename)==0)
printf("\n File %s is renamed to %s",oldfilename,newfilename);
else
printf("\n file %s cannot be renamed",oldfilename);

getch();
}

1 comment:

Rahul-Notes