All languages

C

You're viewing a free preview. Sign in free to read every script.

Why this exists Real programs handle collections of records: servers, log entries, jobs. C has no built in list type, so you build one from a struct, a pointer and realloc. This small pattern (a struct holding a…

C Basics: Structs, Enums and a Growing Dynamic Array

Group data with struct and typedef, name states with enum, then build a resizable array that grows with realloc. Includes the safe realloc pattern that avoids leaking memory when allocation fails, and sorting with qsort.

Sign in free to read this script, along with the rest of the library.

Sign in free