Adjust memory management for problem 40
This commit is contained in:
@@ -9,6 +9,10 @@
|
||||
int split_digits(int* digits, int num)
|
||||
{
|
||||
int len = 0;
|
||||
|
||||
free(digits);
|
||||
digits = malloc(1 * sizeof(int));
|
||||
|
||||
while (num > 0) {
|
||||
len++;
|
||||
|
||||
@@ -33,7 +37,7 @@ int main(int argc, char** argv)
|
||||
int digit = 0, i = 0;
|
||||
int prod = 1, num = 1;
|
||||
|
||||
digits = malloc(0 * sizeof(int));
|
||||
digits = malloc(1 * sizeof(int));
|
||||
if (digits == NULL) {
|
||||
printf("A memory error occurred.\n");
|
||||
exit(1);
|
||||
@@ -53,8 +57,6 @@ int main(int argc, char** argv)
|
||||
/* refill digits and reset i */
|
||||
num++;
|
||||
i = 0;
|
||||
|
||||
memset(digits, 0, len * sizeof(int));
|
||||
len = split_digits(digits, num);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user