diff options
author | Daniel Santos <dacs.git@brilhante.top> | 2022-03-10 18:52:54 +0000 |
---|---|---|
committer | Daniel Santos <dacs.git@brilhante.top> | 2022-03-10 18:52:54 +0000 |
commit | 43398cf34b5b2ac330812d9528c6304fc61f4685 (patch) | |
tree | 4c85f10964faa4b49a5a0029fd4d6458e8e1eb79 | |
parent | 310002d3e0a8b735afe133b502b245b9eee6c11a (diff) | |
download | numericx-c-43398cf34b5b2ac330812d9528c6304fc61f4685.tar.gz |
add (FROM and TO)_FIRST_NUMBER_VOID flags
* add decrement_number_string() * add (FROM and TO)_FIRST_NUMBER_VOID flags Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
-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) ) { |