File Handling · intermediate · ~12 min
Split lines into fields safely.
CSV is deceptively simple. A naive strtok(line, ",") works for basic input but breaks on quoted fields, escaped quotes, embedded newlines, and trailing empty fields.
Use a library (e.g., libcsv) for production. For controlled inputs, a hand parser that handles "…,…" quoting is ~50 lines and a great C exercise.
strtok is destructive and not re-entrant — strtok_r is the thread-safe variant.\r and \n.