← File I/O and Standard LibraryC PROGRAMMING 1.5.D
Standard Library Essentials
The parts of
The handful of <stdlib.h> functions that show up constantly enough to just know cold.
| Function | Does |
|---|---|
atoi / strtol | string to integer — strtol is the one worth actually using, since it can report where parsing stopped and detect overflow |
malloc/calloc/realloc/free | the dynamic memory family from 1.2.F |
qsort | generic sort — takes a comparator function pointer, works on any array type |
exit(code) | terminates immediately, running registered cleanup (atexit) but skipping the rest of the call stack |
rand/srand | pseudo-random numbers — not seeded automatically, needs srand once at startup |
atoi is the one I'd use out of habit, but it has no way to report failure — atoi("abc") just silently returns 0, identical to atoi("0"). strtol distinguishes the two by giving back an end pointer showing exactly where it stopped parsing.
Notes from readers
Comments — via GitHub