basics · intermediate · ~15 min

Find a flag's value

Look up an option's value in argv.

Challenge

Implement const char *flag_value(int argc, char **argv, const char *flag) returning the argument immediately after flag, or NULL if flag is absent or has no following argument.

Starter code

#include <string.h>
#include <stddef.h>

const char *flag_value(int argc, char **argv, const char *flag) {
    /* TODO */
    return NULL;
}

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