各構造体へのポインターと、構造体のポインターを指す void の 2 つの構造体を取得しまし**stack
た。
私の問題はラインにあります
(*ptr2+*a)=(struct student *)malloc(sizeof(struct student));
*a
スタッド登録が発生するたびに 1 ずつ増加する変数なので、同じアドレスに何度もメモリを割り当てません。
メニュー関数でアドレスを送信してからstud(&stud)
、入力関数でアドレスを送信するため
*ptr2==stud
したがって
stud[*a]== *(stud+*a)== *(*ptr2+*a)
なぜ間違っ(*ptr2+*a)
ているの左側にあるのmalloc
ですか?コードの一部
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)
{
...
done=Push(stack,head,(*(int *)ptr2+*a),size);
(*ptr2+*a)=(struct student *)malloc(sizeof(struct student));
stud_input(ptr2,a);
...
}