C - File Handling

C File Handling

  • In C – Programming the files I/O functions handles data on secondary storage device, such as hard disk.
  • In C – Programming the I/O function handles the text files(.txt) into system oriented files.
C File Handling

C File Operations :

  • There are five major operations that can be performed on a file:
    1. Creation of a new file.
    2. Opening an existing file.
    3. Reading data from a file.
    4. Writing data in a file.
    5. Closing a file

Steps for Processing a File :

  1. Declare a file pointer variable.
  2. Open a file using fopen() function.
  3. Process the file using suitable function.
  4. Close the file using fclose() function.

To handle files in C, file input/output functions available in the stdio library are :

  1. fopen - Opens a file.
  2. fclose - Closes a file.
  3. getc - Reads a character from a file
  4. putc - Writes a character to a file
  5. getw - Read integer
  6. putw - Write integer
  7. fprintf - Prints formatted output to a file
  8. fscanf - Reads formatted input from a file
  9. fgets - Read string of characters from file
  10. fputs - Write string of characters to file
  11. feof - Detects end-of-file marker in a file
File operations

Learn C - C tutorial - File Operations - C examples - C programs

Why File Handling in C

  • One more disadvantage is that, it suffers from the performance in writing and reading from the file because data must be converted while writing and reading from the file.
  • We can save the memory and improve the performance by directly writing the binary data on to the file. The file with the binary data is called a binary file. One more advantage with binary file is that, can’t be opened with any other applications.

View More Quick Examples

Related Searches to c file handling

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.