structure and pointers in C -
seg fault again!! please see , correct me
typedef struct entry_s { int key; int value; struct entry_s *next1; } entry_t; entry_t *next2; next2=malloc(sizeof(entry_t)); next2->key=key; // giving seg fault now...
thanks
sizeof(entry_t *) gives 4 bytes nothing size of pointer. need change malloc statement this:
next2=malloc(sizeof(entry_t ));
after malloc add following statement.
memset(next2, 0x00, sizeof(entry_t))
now not segfault.
Comments
Post a Comment