Dec 4, 2024
EOF, typically -1).$ and `).`EOF is reached.FILE type object to hold file information and track access position.
#include <stdio.h> FILE *fp = NULL;NULL to avoid premature dereferencing.*fopen() opens a file and returns a FILE object address.
file_name[], mode[] (e.g., "r", "w", "a").fopen("alpha.txt", "w");NULL if it fails due to permissions or other issues.fclose() disconnects the file from the program.
0; Unsuccessful: EOF.fclose(fp);fprintf(): Formatted write.fputc(): Write single character.fscanf(): Formatted read.fgetc(): Read single character.fprintf() controls format.
int fprintf(FILE *, const char [], ...);fputc() writes a single character.
int fputc(int ch, FILE *fp);fscanf() reads bytes under format control.
int fscanf(FILE *, const char [], ...);fgetc() reads a single character.*rewind(): Resets pointer to beginning of file.feof(): Checks if end-of-file has been read.feof() returns true if end-of-file mark was read.EOF indications.| Function Type | Standard I/O | File I/O | Notes |
|---|---|---|---|
int | scanf(...) | fscanf(fp, ...) | Check for EOF |
int | printf(...) | fprintf(fp, ...) | Returns number of characters written |
int | getchar() | fgetc(fp) | Check for EOF before converting |
int | putchar(ch) | fputc(ch, fp) | Check for EOF |