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>
This commit is contained in:
Daniel Santos 2022-03-10 18:52:54 +00:00
parent 310002d3e0
commit 43398cf34b
1 changed files with 39 additions and 0 deletions

View File

@ -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) )
{