- If you want to tell C that you intend to work with input or
output files,
then include the following line in your program:
#include
- If you want to open an input file,
then instantiate the following pattern:
FILE* file-pointer name;
file-pointer name = fopen(file specification, "r");
- If you want to open an output file,
then instantiate the following pattern:
FILE* file-pointer name;
file-pointer name = fopen(file specification, "w");
- If you want to read data from an open input file,
then substitute
fscanf
for scanf
, and add
a file pointer as the first argument.
- If you want to write data into an open output file,
then substitute
fprintf
for printf
, and add
a file pointer as the first argument.
- If you are finished with an input or output file,
then you should close it by instantiating the
following pattern:
fclose (file-pointer name);