Module 09 of 11

Files, I/O & Error Handling

Lessons

About This Module

Programs that forget everything when they exit are limited. Files let your program save data and load it back later, and they are also where things most often go wrong: a file may be missing, locked, or full. This module covers both sides.

It starts with the basics of file I/O: opening a file with fopen, writing and reading its contents, and closing it again. It then turns to error handling. C has no exceptions, so you check return codes, read errno, and report problems with perror and strerror.

Watch the lessons in order, then continue on to Preprocessor, Headers & Build Tools.

Lessons

5 videos
01

File I/O: Create, Open, Read, Write & Close

A tutorial on file handling in C covering how to create, open, read, write, and close a file.

02

Writing Files

The freeCodeCamp C course chapter on writing data to a file from your program. Starts at the 3:32:37 mark.

03

Reading Files

The freeCodeCamp C course chapter on reading data back from a file. Starts at the 3:41:52 mark.

04

C Error Handling for Beginners

An introduction to handling errors in C: using return codes, errno, and best practices.

05

Error Messages with perror() & strerror()

How to check for failures, report them, and make your C programs more reliable with perror and strerror.