Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void copy(char *target_name,char *source_name)
- {
- char c;
- FILE *target,*source;
- source=fopen(source_name,"r");
- if(source==NULL)
- {
- printf("\nSource file not found");
- }
- target=fopen(target_name,"w");
- while((c=getc(source))!=EOF)
- putc(c,target);
- printf("\nDone.");
- }
- void del(char *file_name)
- {
- int status;
- status = remove(file_name);
- if(status==0)
- printf("\nDone.");
- else
- printf("File not found");
- }
- void rname(char *old_name,char *new_name)
- {
- copy(new_name,old_name);
- delete(old_name);
- }
- int main()
- {
- char s1[50],s2[50];
- int choice;
- printf("Select your option:-\n1.Copy File\n2.Delete File\n3.Rename File\n");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1: printf("Enter source file name:-\n");
- scanf("%s",s1);
- printf("Enter target file name:-\n");
- scanf("%s",s2);
- copy(s2,s1); break;
- case 2: printf("Enter file name:-\n");
- scanf("%s",s1);
- del(s1); break;
- case 3: printf("Enter old name:-\n");
- scanf("%s",s1);
- printf("Enter new name:-\n");
- scanf("%s",s2);
- rname(s1,s2); break;
- default:printf("Error. Enter option again.\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement