When we have finished reading or writing from the file, we need to close it. This is done using the function fclose( ) through the statement.
fclose(fp);
fp is file pointer here.
e.g
A file - copy program here is a program which copies the contents of one file in to another:-
# include "stdio.h"
main( )
{
FILE *fs, *ft;
char ch;
fs = fopen(“pr1.c”, “r”);
if(fs = = NULL)
{
puts(“canot open source file”)’
exit( );
}
ft = fopen (“pr2.c”, “w”);
it (ft = =NULL)
{
puts(“canot open target file”);
fclose(fs);
exit( );
}
while (1)
{
else
}
ch = fgetc(fs);
if(ch = = EOF)
break;
fputc(ch,ft);
fclose(fs);
fclose(ft);
}
fclose(fp);
fp is file pointer here.
e.g
A file - copy program here is a program which copies the contents of one file in to another:-
# include "stdio.h"