about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDaniel Santos <dacs.git@brilhante.top>2022-03-11 15:15:13 +0000
committerDaniel Santos <dacs.git@brilhante.top>2022-03-11 15:18:12 +0000
commitdf82e9e3eb4d62c85554e877213361c6d80243db (patch)
treee3025550b9ca9cdf1603e4a04081fe560fa45621
parent43398cf34b5b2ac330812d9528c6304fc61f4685 (diff)
downloadnumericx-c-df82e9e3eb4d62c85554e877213361c6d80243db.tar.gz
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>
-rw-r--r--numericx.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/numericx.c b/numericx.c
index 07dd870..1b28dfe 100644
--- a/numericx.c
+++ b/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) )