mirror of https://github.com/TheAlgorithms/C
fix dynamic array allocations
This commit is contained in:
parent
9642e1068d
commit
f58916f8f5
|
@ -128,12 +128,13 @@ int main(void)
|
||||||
const int N2 = N + 10;
|
const int N2 = N + 10;
|
||||||
|
|
||||||
// const char N = 50, N2 = N+10; /* length of numbers */
|
// const char N = 50, N2 = N+10; /* length of numbers */
|
||||||
char txt_buffer[N + 5]; /* temporary buffer */
|
char *txt_buffer =
|
||||||
uint8_t number[N]; /* array to store digits of a large number */
|
(char *)calloc(N + 5, sizeof(char)); /* temporary buffer */
|
||||||
uint8_t sum[N2]; /* array to store the sum of the large numbers. For
|
uint8_t *number = (uint8_t *)calloc(
|
||||||
safety, we make it twice the length of a number. */
|
N, sizeof(uint8_t)); /* array to store digits of a large number */
|
||||||
|
uint8_t *sum = (uint8_t *)calloc(
|
||||||
memset(sum, 0, sizeof(sum)); /* initialize sum array with 0 */
|
N2, sizeof(uint8_t)); /* array to store the sum of the large
|
||||||
|
numbers. For safety, we make it twice the length of a number. */
|
||||||
|
|
||||||
FILE *fp = fopen("num.txt", "rt"); /* open text file to read */
|
FILE *fp = fopen("num.txt", "rt"); /* open text file to read */
|
||||||
if (!fp)
|
if (!fp)
|
||||||
|
@ -161,5 +162,8 @@ int main(void)
|
||||||
print_number(sum, N2, 10);
|
print_number(sum, N2, 10);
|
||||||
|
|
||||||
fclose(fp); /* close file */
|
fclose(fp); /* close file */
|
||||||
|
free(txt_buffer);
|
||||||
|
free(sum);
|
||||||
|
free(number);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue