Why is interacting with files important?:
- files allow data to persist after the program has finished executing
- all programs prior to now can only store data for the length of time the program is executing
How to interact with files?:
- declare a file pointer
FILE *file_pointer;- read more about
FILEhere: http://www.cplusplus.com/reference/cstdio/FILE/ - review the lecture on pointers: Pointers Lecture
- read more about
- attach a file to the file pointer
file_pointer = fopen("test.txt", "r");- read more about
fopenhere: http://www.cprogramming.com/tutorial/cfileio.html - understand the different modes to open a file:
r: open for readingw: open for writing (file need not exist)a: open for appending (file need not exist)r+: open for reading and writing, start at beginningw+: open for reading and writing (overwrite file)a+: open for reading and writing (append if file exists)
- read more about
- read/write to the file using
fscanf/fprintf- read more about
fscanfhere: http://www.cplusplus.com/reference/cstdio/fscanf/ - read more about
fprintfhere: http://www.cplusplus.com/reference/cstdio/fprintf/
- read more about
- close the file and file pointer
fclose(file_pointer);- read more about
fclosehere: http://www.cplusplus.com/reference/cstdio/fclose/
- read more about