Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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??
 

Exo

Active Member
initdeq should be

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

egh01

New Member
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;
 

Exo

Active Member
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.

New Articles From Microcontroller Tips

Top