-->
Showing posts with label rename function in C. Show all posts
Showing posts with label rename function in C. Show all posts

neb42:WAP to show use of command “remove” and “rename” in data file handling with the help of example.

ans:
remove:this function is used to delete data file from the system.
syntax is:
remove("filename");

we have following example as a program.

//WAP to show use of command “remove” in data file handling with the help of example.
 #include<stdio.h>
#include<conio.h>
void main()
{
char choice;
printf("enter ur choice\n");
choice=getchar();
if(chice=='y')
        {
              remove("data.txt");
            printf("data file deleted sccessfully\n");
         }
else
{
printf("sorry, data filenot found\n");
}
getch();
}

rename: it is used to rename the file.
syntax is
rename("old name","new name");
 example is given below.
//WAP to show use of command “rename” in data file handling with the help of example.
 #include<stdio.h>
#include<conio.h>
void main()
{
char choice;
printf("enter ur choice\n");
choice=getchar();
if(chice=='y')
        {
              rename("data.txt","data1.txt");
            printf("data file renaming done successfully\n");
         }
else
{
printf("sorry, data file not found\n");
}
getch();
}