Someone
public text v1 · immutable
// this function checks if the input is
// either a number (eg 10) or number,number (eg 15,8)
returns true if the input is valid
bool check_input(const char *s) {
int len = strspn(s, "123456789,");
if(strlen(s) != len) {
return false;
}
char *first_comma = strchr(s, ',');
char *last_comma = strrchr(s, ',');
if(first_comma != NULL) {
if(first_comma != NULL) {
if(first_comma == s || first_comma != last_comma) {
return false;
}
}
}
return true;
}