diff options
Diffstat (limited to 'numericx.c')
-rw-r--r-- | numericx.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/numericx.c b/numericx.c index c5eef26..07dd870 100644 --- a/numericx.c +++ b/numericx.c @@ -76,6 +76,28 @@ increment(numeral_ptr* numeral, char* num_first, char* num_last) ++(numeral->symbol); } +void +decrement_number_string(char* number, char* first_number, char* last_number, char* numeral_system) +{ + while( *number == *first_number ) + { + *number = *last_number; + ++number; + } + + if( *number == '\0' ) + { + *(--number) = '\0'; + } + else + { + while( !(*numeral_system == *number) ) + ++numeral_system; + + *number = *(--numeral_system); + } +} + bool is_the_same(numeral_ptr* numeral, char* number_arg) { @@ -172,6 +194,23 @@ main(int argc, char* argv[]) numeral_ptr* counting = new_digit(NULL, from_first); numeral_ptr* result = new_digit(NULL, to_first); + /* first number void */ + if( !(FROM_FIRST_NUMBER_VOID && TO_FIRST_NUMBER_VOID) ) + { + if( FROM_FIRST_NUMBER_VOID ) + { + if( strlen(number) == 1 && *number == *from_first ) + { + fprintf(stderr, "error: unrepresentable void number\n"); + exit(EXIT_FAILURE); + } + decrement_number_string(number, from_first, from_last, from_first); + } + + if( TO_FIRST_NUMBER_VOID ) + increment(result, to_first, to_last); + } + /* increments until it finishes */ while( !is_the_same(counting, number) ) { |