Hi i'm quite new to C and i'm trying to rewrite a very simple 4 line ptyhon program about dynamic programming and memoization but i'd need to dynamically change my pointer size for that, for some reason this code doesn't work
//Second attempt
#include <stdio.h>
#include <stdlib.h>
void append(struct mem *array, struct mem newItem);
struct mem {
int n;
long long int i;
};
int main() {
struct mem t = {0, 1};
struct mem* test = (struct mem*)calloc(1, sizeof(struct mem));
test[0] = t;
printf("{%d, %d}\n", test[0].n, test[0].i);
struct mem s = {1, 1};
append(test, s);
printf("{%d, %d}", test[0].n, test[0].i);
printf("{%d, %d}", test[1].n, test[1].i);
append(test, s);
printf("{%d, %d}", test[0].n, test[0].i);
printf("{%d, %d}", test[1].n, test[1].i);
printf("{%d, %d}", test[2].n, test[2].i);
//ignore messy code lol
return 0;
}
void append(struct mem *array, struct mem newItem) {
array = (struct mem*)realloc(array, sizeof(array)+sizeof(struct mem));
printf("%d\n", sizeof(array)/sizeof(struct mem)+1);
int index = sizeof(array)/sizeof(struct mem)+1;
array[index] = newItem;
}