|
TAGS |
"r" / "rb" |
Read existing text/binary file. |
"w" / "wb" |
Write new/over existing text/binary file. |
"a" / "ab" |
Write new/append to existing text/binary file. |
"r+" / "r+b" / "rb+" |
Read and write existing text/binary file. |
"w+" / "w+b" / "wb+" |
Read and write new/over existing text/binary file. |
"a+" / "a+b" / "ab+" |
Read and write new/append to existing text/binary file. |
RANDOM-ACCESS |
fread(void *buf, sizeof(element), number, fptr) |
Reads a number of elements from fptr to array *ptr. (safe) |
fwrite(void *buf, sizeof(element), number, fptr) |
Writes a number of elements to file fptr from array *ptr. |
SEQUENCIAL |
fscanf(fptr, format, [...]) |
Same as scanf with additional file pointer parameter. (unsafe) |
fprintf(fptr, format, [...]) |
Same as printf with additional file pointer parameter. |
fgets(strName, length, fptr); sscanf(strName, "%d", &x); |
Uses fgets to limit the input length, then uses sscanf to read the resulting string in place of scanf. (safe) |
NAVIGATION |
fseek(fptr, offset, origin); |
Sets current file position. Returns false is successful, true otherwise. The offset is a long integer type. |
ftell(fptr) |
Return current file position as a long integer. |
SEEK_SET |
Beginning of file. |
SEEK_CUR |
Current position in file. |
SEEK_END |
End of file. |
feof(fptr) |
Tests end-of-file indicator. |