Link to home
Start Free TrialLog in
Avatar of zizi21
zizi21

asked on

Stack :Urgent...

Hi ,

I am having some problems with stacks. I am debugging it.

Is this the way to create stacks?

typedef struct numbers{
int num1;
int num2;
}NUM;

typedef struct stack
{
    NUM *rows;
    int n;
    int topofstack;
}STA;

in create function..

s->n=10;
s->topofstack=0;
s->rows=malloc(s->n*sizeof(NUM *));

in push function..

s->topofstack+=1;
s->rows[s->topofstack].num1=0;
s->rows[s->topofstack].num2=10


this is where i think the problem is ...
in the create function, i have malloced an array of pointers...
now here, do i malloc for an item ?or this is fine?
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zizi21
zizi21

ASKER

thank you very much...
Avatar of zizi21

ASKER

thank you.