File operations in c

Files are the foremost visible and therefore the most precious feature of any computing system to its users. Files provide a mechanism for the long term storage of data. 

They remain to exist even if the computer is switched off. Files are stored within the concentric circular tracks of a floppy or a tough disk.Before a file are often used for reading or writing , it must be opened. 

This is done by a call to the fopen() function. The function fopen() requires two arguments :

1. File name

2. Option (r, w, a, etc)

Option indicates what we want to do with the file :

(a) read it
(b) write to it
(c) append to it (writing at the end). 


Below are the file opening options for text files:

  • r          This option opens existing file for reading the content in it.
  • w         This option opens(creates file if not present) and it deletes previous content.
  • a         This option opens(and makes file if needed) and this option does not delete previous content             and writes at the end of file.
  • r+        This option opens existing file for reading and writing. It behaves like 'r' (read                 only) with the option of writing.
  • w+       This option creates and open file for reading and writing, it deletes previous                      content. It behaves like 'w'(write) with the option of reading.
  • a+        This option opens (creates if file not present) file for reading and adding                           content in file. It behaves like 'a' with the option for reading. 



Newest
Previous
Next Post »