Skip to main content

File Operations in C

File operations follow four steps every time:
  1. Declare a file pointer
  2. Open the file with the appropriate mode
  3. Perform operations (read/write)
  4. Close the file

1. Writing to a File

After running this, a file named write.txt is created in the same directory containing the two lines.

2. Reading from a File

Output:

3. Appending to a File


4. Character-by-Character Read

EOF (End Of File) is a constant that signals no more data is available.

Summary of Modes