linux-sysprog · beginner · ~15 min

Length of an argv vector

Walk a NULL-terminated pointer array.

Challenge

exec takes a NULL-terminated argv array. Implement int argv_len(const char *const *argv) returning the number of arguments before the terminating NULL.

Starter code

#include <stddef.h>

int argv_len(const char *const *argv) {
    /* TODO */
    return 0;
}

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