file-handling · beginner · ~15 min

Count CSV fields

Tokenise a delimited line by counting separators.

Challenge

Implement int csv_field_count(const char *line) returning the number of comma-separated fields in line. An empty string has 0 fields; otherwise it's commas + 1.

Starter code

int csv_field_count(const char *line) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.