Comprehensive notes for Chapter 14 File Handling in C. Covers streams, text vs binary files, file opening modes, and I/O functions like fopen, fclose, fprintf, fscanf.
Definition: A logical interface to a file is known as a stream. It is a flow of data.
Opening a File (fopen): Associates a file with a stream. Syntax: FILE *fp = fopen("filename", "mode");
Closing a File (fclose): Disconnects the file from the program. Syntax: fclose(fp);
Modes:
"r": Read only (file must exist)."w": Write only (creates new or overwrites existing)."a": Append (adds to end, creates if not exists)."r+": Read/Write (file must exist)."w+": Read/Write (overwrites/creates)."a+": Read/Append.fgetc() (read char), fputc() (write char).fgets() (read string), fputs() (write string).fscanf() (read formatted data), fprintf() (write formatted data).FILE that points to the information required to manage a file.