cmpsc 311 test 2 IO Flashcards
fopen() syntax
FILE *fopen(const char *path, const char *mode);
IO, pointer
the fopen function opens a file for — and returns a —- to a FILE* structure
stream
A FILE* structure is also referred to as a —-
r
–: open text file for reading. The stream is positioned at the beginning of the file
r+
— Open for reading and writing. The stream is positioned at the beginning of the file
w
–: truncate file to zero length or create text file for writing. the stream is positioned at the beginning of the file
w+
—: Open for reading and writing. The file is created if it does not exist, otherwise it is truncated
a
Open for appending (writing at the end of file). The file is created if it does not exist
a+
Open for reading and appending (writing at end of file). the file is created if it does not exist
fscanf, fgets
there are two dominant ways to read the file: ——- and ——
fscanf, scanf
— reads the data from the file just like —–, just reading and writing
fgets
— reads a line of text from the file
fprintf, fputs
there are two dominant ways to write the file, —- and —-
fprintf, printf
— writes data to the file just like —-, just reading and writing
fputs
—- writes a line of text to the file
FILE*
—- based IO is buffered
fflush
—- attempts to reset/the flush state
int fflush(FILE *stream)
fflush syntax
buffered, written, pushed, OS/disk
FILE* based writes are —–, so there may be data ——-, but not yet —– to the —/—–
fflush()
—– forces a write of all buffered data
buffered, current, current
FILE* based reads are —-, so the — data (in the process space) may not be —-
fflush()
—– discards buffered data from the underlying file
NULL, fflush, all
If the stream argument is —–, ——() flushes —- open output streams
fclose()
—– closes the file and releases the memory associated with the FILE* structure
storage
fclose() implicitly flushes the data to ——
file, integer file handle
the open function opens a —- for IO and returns an —— —— —–
int open(const char *path, int flags, mode_tmode);
open() syntax
path
open():
— is a string containing the absolute or relative path to the file to be opened
flags
open():
— indicates the kind of open you are requesting
mode
open():
—- sets a security policy for the file
file handle
open() returns a —- —-