Program to copy any file using FILE method
#include<stdio.h>
main()
{
char in_name[25],out_name[25];
FILE *in, *out;
char c;
printf("Enter name of file to copy :");
scanf("%s",in_name);
printf("\nEnter name to copy it :");
scanf("%s",out_name);
if((in=fopen(in_name,"r"))==(FILE*)NULL)
printf("Could not open %s for reading.\n",in_name);
else if ((out=fopen(out_name,"w"))==(FILE*)NULL)
printf("\nCould not open %s for writing.\n",out_name);
else
{
while((c=getc(in))!=EOF)
putc(c,out);
printf("\nFile has been created.\n");
}
getch();
}
Comments
Post a Comment