Opening a File In C

Before performing any file I/O, the file must be opened. While opening the file,the following are specified:

  • • The name of the file
  • • The manner in which it should be opened (i.e., for reading, writing ,both reading and writing, appending at the end of the file, overwriting the file,etc.)

The function fopen() is used to open a stream for use and links a file with that stream. it accepts two strings, the first is the name of the file, and the second is the mode in which it should be opened. Then it returns the file pointer associated with that file. The prototype of the fopen () function is given below:

FILE *fopen(const char *file_name, const char*mode);

Where file_name is a pointer to a string of characters that make up a valid file name and the mode determines how the file will be opened. The fopen function returns a file pointer. If an error occurs when it is trying to open the file, fopen () returns a null pointer.

Below table shows the different modes of opening a file.

img

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext