Any expert in C landuage would help!!!

Status
Not open for further replies.

linkj

New Member
typedef struct node {
Itemtype item;
struct node *next;
} Node;

typedef struct deqstruct{
Node *front;
Node *back;
int size;
} *Deq;

void initdeq(Deq *d)
{
(*d)->size = 0;
(*d)->front = NULL;
(*d)->back = NULL;
}

does the initialization looks right to u???
it is compiled, but it got segmentation fault (core dumped) when i run it.
can any one tell me why??
 
initdeq should be

void initdeq(Deq *d)
{
d->size = 0;
d->front = NULL;
d->back = NULL;
}
 
Why do you typedef/declare the the deqstructure as a pointer? (*Deq)

When you do that you get an segmentation error when you assign size the way you do. Try with:

typedef struct deqstruct{
...
} Deq;
 
It could be he dynamically allocates memory for the structure (wich i assumed).

If not, then you're right egh01.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…