Fopen
Syntax:
#include <stdio.h> FILE *fopen( const char *fname, const char *mode ); |
Fopen () functionFname(File Name) specifies the file and returns a stream associated with the file. If an error occurs, fopen () returns NULL.Mode(Method) is used to determine the purpose of the file (for example, used for input, output, and so on)
Mode) |
Meaning |
"R" |
Open a text file for reading |
"W" |
Create a text file for writing |
"" |
Attach to a text file |
"Rb" |
Open a binary file for reading |
"WB" |
Create a binary file for writing |
"AB" |
Attaches to a binary file |
"R +" |
Open a text file for reading/writing |
"W +" |
Create a text file for reading/writing |
"A +" |
Open a text file for reading/writing |
"RB +" |
Open a binary file for reading/writing |
"WB +" |
Create a binary file for reading/writing |
"AB +" |
Open a binary file for reading/writing |
Example:
char ch; FILE *input = fopen( "stuff", "r" ); ch = getc( input );