Wednesday, 20 February 2013

Program:To write a c program that makes a copy of a file using standard I/O ..

Program:To write a c program that makes a copy of a file using standard I/O ..

#include
#include
#include
#include
main(int argc,char *argv[])
{
FILE *fp1,*fp2;
char ch;
int i;
fp1=fopen(argv[1],"r");
if(fp1==NULL)
{
printf("Source file does not exist");
}
else
{
fp2=fopen(argv[2],"w");
while(!feof(fp1))
{
ch=fgetc(fp1);
fputc(ch,fp2);

}
fclose(fp2);
fclose(fp1);
printf("File copied");
}
}



/*----------------------INPUT/OUTPUT--------------
bash-3.2$ cc copy.c -o copy
-bash-3.2$ ./copy f1.c f2.c
File copied

---------------------------------------------------*/

No comments:

Post a Comment