I got a void **stack which contains the addresses of the struct pointers my problem is that when I print the whole stack different addresses are shown than the actual addresses I'm actually trying to save in the stack.
I've tested if stud_input works correctly by printing the content of the struct and it seems to work fine.
I normally have 1 more struct(struct professor) but I got the same prob for both so I'm not posting both to make it less complicated.
example of what I expect to be printed vs what I really get when I print the addresses
Expected:
5836544
5836851
5837158
What i really get:
5836544
5836545
5836546
part of the code
struct student
{
char flag;
char surname[256];
int semester;
};
main()
{
struct student *stud;
//....
menu(stack,stackcopy,reversedstack,&prof,&stud,stacksize,&head);
//....
}
void menu(void **stack,void **stackcopy,void **reversed,struct professor **ptr1,struct student **ptr2,int size,int *head)
{
//....
input(stack,ptr1,ptr2,size,head,&a,&b);
//.....
}
int input(void **stack,struct professor **ptr1,struct student **ptr2,int size,int *head,int *a,int *b)
{
// *a and *b are variables that increase by one each time a student registration happens to change the add of the struct pointer every time
int i,done=0,stud_or_prof=-1;
//....
*(ptr2+*a)=(struct student *)malloc(sizeof(struct student));
done=Push(stack,head,(*(int *)ptr2+*a),size);
if (done==1)
stud_input(ptr2,a);
else
free(*(ptr2+*a));
//...
}
int Push(void **stack,int *H,int element,int size)
{
if (*H==(size))
return 0;
*((int *)stack+*H)=element;
(*H)++;
return 1;
}