linux-sysprog · intermediate · ~15 min

Count command arguments

Tokenise a command line.

Challenge

A shell splits a command line on whitespace. Implement int count_args(const char *line) returning the number of whitespace-separated tokens.

Starter code

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

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