by-character basis.
Solution 6:
The following is the
file copy
program (i.e., from source file to destination file):
#include
#include
void main( )
{
FILE *fp, *ft;
char ch;
clrscr( );
if ((fp = fopen(“file1.dat”, “r”)) = =NULL)
{
printf(“\n Cannot open source file”);
exit(1);
}
if ((fp = fopen(“file2.dat”, “w”)) = =NULL)
{
printf(“\n Cannot open target file”);
exit(1);
}
while (1)
{
if ((ch = = fgetc (fp)) != EOF)
fputc (ch, ft);
else
break;
}
fclose (fp);
fclose(ft);
}
Example
Do'stlaringiz bilan baham: |