diff options
-rw-r--r-- | numericx.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/numericx.c b/numericx.c index 44cd648..d12fc87 100644 --- a/numericx.c +++ b/numericx.c @@ -177,6 +177,22 @@ reverse_string(char* string) } } +bool is_valid_number(char* numeral_system, char *number) +{ + /* + if( *number == '-' || *number == '+' ) + ++number; + */ + while( !(*number == '\0') ) + { + if( strchr(numeral_system, *number) == NULL ) + return false; + ++number; + } + + return true; +} + int main(int argc, char* argv[]) { @@ -199,6 +215,13 @@ main(int argc, char* argv[]) /* Number variables to be converted */ char* number = argv[1]; + /* Check if number belongs to it's numerical system */ + if( !is_valid_number(from, number) ) + { + fprintf(stderr, "error: %s.\n", strerror(EDOM)); + exit(EDOM); + } + /* _first and _last variables */ char* from_first = from; char* from_last = from + (strlen(from) - 1); |