File handling in C

File handling in C 
  • In programming, we may require some specific input data to be generated several numbers of times. Sometimes, it is not enough to only display the data on the console. 
  • The data to be displayed may be very large, and only a limited amount of data can be displayed on the console, and since the memory is volatile, it is impossible to recover the programmatically generated data again and again. 
  • However, if we need to do so, we may store it onto the local file system which is volatile and can be accessed every time. Here, comes the need of file handling in C.
File handling in C enables us to create, update, read, and delete the files stored on the local file system through our C program. The following operations can be performed on a file.
  • Creation of the new file
  • Opening an existing file
  • Reading from the file
  • Writing to the file
  • Deleting the file
Functions for file handing : 
No. Function Description
  1. fopen() opens new or existing file
  2. fprintf() write data into the file
  3. fscanf()  reads data from the file
  4. fputc() writes a character into the file
  5. fgetsc() reads a character from file
  6. fclose() closes the file
  7. fseek() sets the file pointer to given position
  8. fputw() writes an integer to file
  9. fgetw() reads an integer from file
  10. ftell() returns current position
  11. frewind() sets the file pointer to the beginning of the file
Posted on by