#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
char *buff,*t1,*t2,*t3,ch;
FILE *fp1,*fp2;
main()
{
int n;
clrscr();
while(1)
{
printf("myshell$");
fflush(stdin);
t1=(char *)malloc(80);
t2=(char *)malloc(80);
t3=(char *)malloc(80);
buff=(char *)malloc(80);
fgets(buff,80,stdin);
n=sscanf(buff,"%s %s %s",t1,t2,t3);
if(strcmp(t1,"exit")==0)
exit(0);
if(strcmp(t1,"mv")==0)
{
if(rename(t2,t3)==-1)
perror(" ");
else
{
rename(t2,t3);
printf("\n%s file is moved successfully into %s file",t2,t3);
}
}
else if(strcmp(t1,"rm")==0)
{
if(remove(t2)==-1)
perror(" ");
else
{
remove(t2);
printf("\n%s File is deleted",t2);
}
}
else if(strcmp(t1,"cp")==0)
{
fp1=fopen(t2,"r");
fp2=fopen(t3,"w");
if(fp1==NULL)
printf("\nError in opening file %s",t2);
while(1)
{
ch=fgetc(fp1);
if(ch==EOF)
break;
fputc(ch,fp2);
}
fcloseall();
}
}
}
Post a Comment