add FROM_INFINITE_BASE flag
* defines both (TO and FROM)_INFINITE_BASE * add FROM_INFINITE_BASE functionality Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
This commit is contained in:
parent
43398cf34b
commit
df82e9e3eb
34
numericx.c
34
numericx.c
|
@ -24,6 +24,14 @@
|
|||
#define FROM_FIRST_NUMBER_VOID false
|
||||
#endif
|
||||
|
||||
#ifndef TO_INFINITE_BASE
|
||||
#define TO_INFINITE_BASE false
|
||||
#endif
|
||||
|
||||
#ifndef FROM_INFINITE_BASE
|
||||
#define FROM_INFINITE_BASE false
|
||||
#endif
|
||||
|
||||
typedef struct NumeralPtr
|
||||
{
|
||||
char const* symbol;
|
||||
|
@ -55,6 +63,21 @@ new_digit(numeral_ptr* last_numeral, char const* to_first)
|
|||
return starting_point;
|
||||
}
|
||||
|
||||
numeral_ptr*
|
||||
numeral_infinity(char const* to_first, size_t cases)
|
||||
{
|
||||
numeral_ptr* starting_case = new_digit(NULL, to_first);
|
||||
numeral_ptr* other_case = starting_case;
|
||||
|
||||
for(size_t i = 2; i <= cases; ++i)
|
||||
{
|
||||
other_case->next = new_digit(other_case, to_first);
|
||||
other_case = other_case->next;
|
||||
}
|
||||
|
||||
return starting_case;
|
||||
}
|
||||
|
||||
void
|
||||
increment(numeral_ptr* numeral, char* num_first, char* num_last)
|
||||
{
|
||||
|
@ -191,8 +214,15 @@ main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
/* initializing counting and result */
|
||||
numeral_ptr* counting = new_digit(NULL, from_first);
|
||||
numeral_ptr* result = new_digit(NULL, to_first);
|
||||
numeral_ptr* counting = NULL;
|
||||
numeral_ptr* result = NULL;
|
||||
|
||||
if( FROM_INFINITE_BASE )
|
||||
counting = numeral_infinity(from_first, strlen(number));
|
||||
else
|
||||
counting = numeral_infinity(from_first, 1);
|
||||
|
||||
result = numeral_infinity(to_first, 1);
|
||||
|
||||
/* first number void */
|
||||
if( !(FROM_FIRST_NUMBER_VOID && TO_FIRST_NUMBER_VOID) )
|
||||
|
|
Loading…
Reference in New Issue