Program to copy one file into another using character arrays.



#define MAX 80
#include
#include

main()
{
FILE *fs, *ft;
static char sfn[MAX];
static char tfn[MAX];
char ch, str[MAX];

puts("Enter source filename.");
gets(sfn);

if((fs = fopen(sfn, "r")) == NULL)
{
puts( "Source file does not exists.");
exit(0);
}

puts("Enter target filename");
gets(tfn);

if(fp = fopen (tfn, "w") == NULL )
{
puts("Target file cannot be created.");
fclose(fs);
exit(0);

}
while(1)
{
if (fgets(str, fs=NULL) fputs (str, ft);
else
break;
fclose(fs);
fclose(ft);
}
}

No comments:

Post a Comment