Show Menu
Cheatography

C File IO Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

FILE * fout = fopen(­FIL­E_P­ATH­," ")

r
open for reading
w
open for writing (file need not exist)
a
open for appending (file need not exist)
r+
open for reading and writing, start at beginning
w+
open for reading and writing (overwrite file)
a+
open for reading and writing (append if file exists
fclose­(fout) close the file

Basic Functions

fgets(char str, int n, FILE stream)
fgetc(FileOut) -self increment-
fscanf(FILE stream, FORMAT, char buf)
ftell(FILE *stream) -rtrn file position long int-
fputs(const char str, FILE stream)
 

fseek(FILE *stream, long int offset, int whence)

offset
This is the number of bytes to offset from whence.
whence
This is the position from where offset is added. It is specified by one of the following constant
stream
This is the pointer to a FILE object that identifies the stream.

fread(void ptr, size, nmemb, FILE stream)

ptr
This is the pointer to a block of memory with a minimum size of size*nmemb bytes.
size
This is the size in bytes of each element to be read.
nmemb
This is the number of elements, each one with a size of size bytes.
stream
This is the pointer to a FILE object that specifies an input stream.
size_t, same with fwrite