linux-sysprog · beginner · ~15 min
Read the environment with a fallback.
Implement const char *getenv_or(const char *name, const char *dflt) returning the environment variable name, or dflt if it is unset.
#include <stdlib.h>
const char *getenv_or(const char *name, const char *dflt) {
/* TODO */
return dflt;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.