basics · intermediate · ~15 min
Encode acceptance rules as states.
Implement int valid_number(const char *s) returning 1 if s is an optional '+'/'-' sign followed by one or more decimal digits and nothing else, else 0. Empty string is invalid.
int valid_number(const char *s) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.