Files in C

Open a File

FILE *fopen(char *filename, char *mode)

Modes:

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.

cat.c