basics · intermediate · ~15 min

Validate a format string

Validate input while scanning.

Challenge

Implement int is_valid_format(const char *fmt) returning 1 if every % is followed by one of d s c x % (and not by end-of-string), else 0.

Starter code

int is_valid_format(const char *fmt) {
    /* TODO */
    return 0;
}

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