fopen

The fopen function opens a file in the file system and returns a pointer to a FILE structure, which can be used later for further read/write access.

The fopen function requires two arguments. The first argument is the name of the file to be opened, given as a null terminated string. The second argument is also a string, but it encode the type of access to the file. For example:

The return value of the fopen function is a pointer to a FILE structure. The value of this pointer is NULL if there was any problem while opening the file. Otherwise, the pointer is for a valid FILE structure that can be used in further accesses to the file.

In normal circumstances, every call to fopen should correspond to a call to fclose. However, when a program ends all open files are closed automatically by the operating system, so it is not necessary to call fclose if this is the last step of a program.

Article created on 2008-08-19 21:55:36

Post a comment