C File Handling Functions


These are basic file operations to perform.

  • fopen(): it creates a new file or opens an existing file.
  • fclose(): it closes a fileseparately.
  • getc(): it reads a character from a file.
  • putc(): it writes a character to a file.
  • fscanf(): it reads a set of data from a file.
  • fprintf(): it writes a set of data to a file.
  • getw(): it reads an integer to a file.
  • putw(): it writes an integer to a file.
  • fseek(): it is used to set the position to aspiration point.
  • ftell(): it is used to give present position in the file.
  • rewind(): it set the position to the starting point.

Example:

#include <stdio.h>
#include <stdlib.h> 

void main()
{
	FILE *fp;
	char c;
	fp=fopen("TEST.txt","r");
	while(1){
		c=fgetc(fp);
		if(feof(fp))
			break;
		printf("%c",c);
	}
	fclose(fp);
}



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.