Open a File
FILE *fopen(char *filename, char *mode)
Modes:
r | Open for reading. |
w | Open for writing. File is truncated. |
r+ | Open for reading and writing. |
w+ | Open for reading and writing. File is truncated if it exists. |
a | Open for appending. |
a+ | Open for reading and appending. |
Close a File
int fclose(FILE *stream)
Reading From a File
int fscanf(FILE *stream, char *format, ...)
char *fgets(char *s, int size, FILE *stream)
int fgetc(FILE *stream)
int getc(FILE *stream)
Writing to a File
int fprintf(FILE *stream, char *format, ...)
char *fputs(char *s, FILE *stream)
int fputc(int c, FILE *stream)
int putc(int c, FILE *stream)
I/O Errors
#include <errno.h>
#include <string.h>
The global integer variable errno
stores a status code for the last I/O
operation.
strerror(errno)
returns a string that describes the error associated with the
error code in errno.