c - Malloc Member Array of Struct -
i have struct , dynamic array inside struct. want malloc array don't how. want array void because want members of array structs. can see tried doesn't work
#include <stdio.h> #include <stdlib.h> #include <string.h> struct saf { int head; void **stack; int size; }exp1; void init(int n) { struct saf exp1->stack = malloc(n); } int main() { printf("give size: "); scanf("%d",&exp1.size); init(exp1.size); return 0; }
exp1 isn't pointer. use
exp1.stack = malloc(n);
Comments
Post a Comment