All pastes #12983 Raw Edit

Someone

public text v1 · immutable
#12983 ·published 2005-05-30 21:43 UTC
rendered paste body

// 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;
}