My test results and test code.
Code:
testValue.size:= 10
1234567890
12345678910
0
0
99
9000000000
99999999910
Error: NULL pointer passed to print function
10000000000
0
999990000
1000000
999998000001
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct integer {
int* digits;
int size;
};
/* Make all the digits 9 or less by carrying the value to next higher digit */
/* WARNING returns NULL pointer if size is too small */
struct integer* normalize_digits(struct integer *p);
/* Reduce the size by how many leading digits are zero; min size is 1 */
struct integer* normalize_size(struct integer *p);
void print(struct integer *p);
struct integer* convert_integer(char* stringInt);
struct integer* multiply(struct integer *p, struct integer *q);
int main()
{
struct integer testValue3;
int testDigits3[] = {10,9,9,9,9,9,9,9,9,9};
testValue3.digits = testDigits3;
testValue3.size = sizeof(testDigits3)/sizeof(testDigits3[0]);
struct integer testValue2;
int testDigits2[] = {10,9,9,9,9,9,9,9,9,8};
testValue2.digits = testDigits2;
testValue2.size = sizeof(testDigits2)/sizeof(testDigits2[0]);
struct integer testValue;
int testDigits[] = {0,9,8,7,6,5,4,3,2,1};
testValue.digits = testDigits;
testValue.size = sizeof(testDigits)/sizeof(testDigits[0]);
printf("testValue.size:= %d\n", testValue.size);
print(&testValue);
print(convert_integer("12345678910"));
#if 1 /* change 1 to 0 to disable this code section */
print(normalize_size(convert_integer("0000000"))); /* 0 */
print(normalize_size(convert_integer("0"))); /* 0 */
print(normalize_size(convert_integer("99"))); /* 99 */
print(normalize_digits(&testValue2)); /* 9000000000 */
print(&testValue3); /* 99999999910 */
print(normalize_digits(&testValue3)); /* NULL POINTER */
print(&testValue3); /* 10000000000 */
#endif
print(multiply(convert_integer("1000"), convert_integer("0"))); /* 0 */
print(multiply(convert_integer("99999"), convert_integer("10000"))); /* 999990000 */
print(multiply(convert_integer("1000"), convert_integer("1000"))); /* 1000000 */
print(multiply(convert_integer("999999"), convert_integer("999999"))); /* 999998000001 */
return 0;
}
No plans to work on this anymore; the major thinking for me is solving the lower level functions. The read and process of the data file holds no interest. Nothing for me to learn doing it. And if I did it, I might be temped to post it; that much help is against the idea of this site.
Edit: Both my normalize_ functions returns the pointer passed to it; except in errors where NULL pointer is returned.
This allows easier testing.
Tim S.