I can init all of memory for node parameters, now I just want initialize one of the struct parameters (node-> nb ), but have error
My code
#define v 10
typedef struct node_type{
int id;
int nb[v];
bool link_capacity;
}node_t;
int main()
{
int i,j;
node_t *node;
node = (node_t *) malloc(v*sizeof(node_t));
memset(node, 0, v*sizeof(node_t));
node[0].nb[0]=1;
node[1].nb[0]=2;
node[0].id=1;
node[1].id=2;
printf("%d %d %d %d\n",node[0].nb[0],node[1].nb[0],node[0].id,node[1].id);
memset(node->nb, 0, v*sizeof(node_t));
printf("%d %d %d %d\n",node[0].nb[0],node[1].nb[0],node[0].id,node[1].id);
return 0;
}
Ans:
1 2 1 2
0 0 1 0
But I hope that Ans:
1 2 1 2
0 0 1 2
How to modify?