C Programming language

C - General Structure of File program, Some function used for File Handling
Previous Home Next

General structure of file program

#include <stdio.h>
main( )
FILE * fp1;
* Open any file .txt format file and mode( read, write, append)
fp1=fopen("filename","mode" ); 

End of file: The file reading function need to know the end of file so that they can stop reading. When the end of file is reached , the operating signal send s an end of file signal to the program. When the program receive this signal , the file reading function return EOF which is constant defined in the file <stdio.h> an its value -1 . EOF is an integer value so make sure the return value of the function is assigned to a integer variables.

Some Function used for file Handling
Character I/O fgetc( ), fputc( ), getc( ), putc( )
String I/O fgets( ), fputs( )
Integer I/O getw( ), putw( )
Formatted I/O fscanf( ), fprintf( )
Record I/O fread( ), fwrite( )
Previous Home Next