fopen
Syntax:
#include <stdio.h>
FILE *fopen( const char *fname, const char *mode );
The fopen() function opens a file indicated by fname and
returns a stream associated with that file. If there is an error, fopen()
returns NULL. mode is used to determine how the
file will be treated (i.e. for input, output, etc)
Mode |
Meaning |
"r" |
Open a text file for reading |
"w" |
Create a text file for writing |
"a" |
Append to a text file |
"rb" |
Open a binary file for reading |
"wb" |
Create a binary file for writing |
"ab" |
Append to a binary file |
"r+" |
Open a text file for read/write |
"w+" |
Create a text file for read/write |
"a+" |
Open a text file for read/write |
"rb+" |
Open a binary file for read/write |
"wb+" |
Create a binary file for read/write |
"ab+" |
Open a binary file for
read/write |
An example:
int ch;
FILE *input = fopen( "stuff", "r" );
ch = getc( input );
Related topics: