-
malloc in structures
I was wondering if u could malloc in a structure parts at a t time.
Code:
typedef struct {
char part[10];
char part2[20];
randomstruct * ptr;
} struct1;
Is there a way to malloc space for the part and part2 without touching the pointer for randomstuct
like
struct1 test;
test->part = malloc(sizeof(part));
???????
-
You would need to declare them as pointers.
Code:
typedef struct {
char* part;
char* part2;
randomstruct * ptr;
} struct1;
struct1 test;
test.part = malloc(10);
test.part2 = malloc(20);