CodeRigor

FREE COURSE / REAL PRACTICE

C standard library (C++)

Use C library interfaces from C++: bounded bytes and strings, conversions, allocation, FILE streams, formatting, callbacks and time.

Free lessons & exercises9 authored lessons3 units

What you’ll work toward

Keep bounds, errors and ownership explicit while adapting low-level C interfaces to C++ resource management.

Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.

Before you start

This course builds on these skills:

Individual lessons can add prerequisites. The course map shows your actual readiness.

A look inside the first lesson

Byte buffers & memory functions

C++
#include <array>
#include <cstddef>
#include <cstdio>
#include <cstring>
int main() {
    std::array<unsigned char,6> bytes{10,20,30,40,50,60};
    std::memmove(bytes.data()+2,bytes.data(),4);
    for(auto b:bytes) std::printf("%u ",unsigned(b));
    std::puts("");
}

Your course outline

Follow the lessons in curriculum order. Open a unit to preview the ideas you’ll work with.

UNIT 013 lessons C library: bytes, strings & characters
  1. LESSON 01.01

    Byte buffers & memory functions

    Validate byte ranges before calling memmove; distinguish overlap, byte counts and object representation from typed value operations.

    Open lesson
  2. LESSON 01.02

    C strings, terminators & bounded adapters

    Keep byte length, buffer capacity and NUL termination distinct; use memchr to inspect bounded storage and copy text without silent truncation.

    Open lesson
  3. LESSON 01.03

    Character classification, locale & byte text

    Use cctype with unsigned-byte values, trim C-locale whitespace, and separate byte-oriented case conversion from Unicode text processing.

    Open lesson
UNIT 023 lessons C library: conversion, allocation & streams
  1. LESSON 02.01

    Checked numeric conversion & errno

    Combine strtol/strtod, end pointers, errno and destination bounds; reject incomplete tokens, embedded NUL, whitespace, overflow and nonfinite numbers.

    Open lesson
  2. LESSON 02.02

    malloc, calloc, realloc & ownership

    Own C-allocated byte storage, check size products before allocation, preserve the old block on realloc failure and release with the matching allocator.

    Open lesson
  3. LESSON 02.03

    FILE streams, buffering & binary I/O

    Use fread/fwrite counts, distinguish EOF from stream errors, and flush buffered output while keeping FILE ownership explicit.

    Open lesson
UNIT 033 lessons C library: formatting, callbacks & time
  1. LESSON 03.01

    Format strings, snprintf & bounded input

    Match variadic format arguments exactly, interpret snprintf counts and truncation, and separate trusted formats from input data.

    Open lesson
  2. LESSON 03.02

    qsort, bsearch & C callbacks

    Sort trivially copyable records with an overflow-safe C comparator, then search by key without assuming stable order or a particular duplicate match.

    Open lesson
  3. LESSON 03.03

    Calendar time, CPU clocks & formatting

    Distinguish time_t, tm and clock_t; format validated calendar fields and convert CPU ticks without assuming a Unix epoch or wall-clock timing.

    Open lesson