cybersecurity · intermediate · ~15 min

Validate an integer in range

Parse and range-check numeric input.

Challenge

Implement int valid_int_in_range(const char *s, int lo, int hi) returning 1 if s is a valid base-10 integer within [lo, hi], else 0.

Starter code

#include <stdlib.h>

int valid_int_in_range(const char *s, int lo, int hi) {
    /* TODO */
    return 0;
}

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