basics · intermediate · ~15 min

Count flag arguments

Iterate argv the way a CLI parser does.

Challenge

Implement int count_flags(int argc, char **argv) returning how many arguments (excluding argv[0]) start with '-'.

Starter code

int count_flags(int argc, char **argv) {
    /* TODO */
    return 0;
}

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