file-handling · intermediate · ~15 min
Walk delimited text to a specific field.
Implement int csv_get_field(const char *line, int idx, char *out, int outsz) copying the 0-based field idx into out (NUL-terminated, bounded by outsz) and returning its length, or -1 if idx is out of range.
#include <string.h>
int csv_get_field(const char *line, int idx, char *out, int outsz) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.