Home > Back-end >  Why will p=p -> next to p complains??
Why will p=p -> next to p complains??

Time:10-03

# define _CRT_SECURE_NO_WARNINGS
# include
# define N 3
Struct student
{
int num;
Char name [50].
Char sex;
Int the age;
Struct student * next;
};
Void input (struct student * stu)
{
Struct student * p;
int i=0;
For (p=stu. P & lt; Stu + N. P++ i++)
{
Printf (" % d: ", I + 1);
The scanf (" % d % s % c % d ", & amp; P - & gt; Num, p - & gt; The name, & amp; P - & gt; Sex, & amp; P - & gt; The age);
I==N - 1? (stu [I] next=NULL) : (stu [I] next=& amp; Stu [I + 1));
}
}
Void print (struct student * stu)
{
Struct student * p;
For (p=stu. P - & gt; Next!=NULL; P=p - & gt; Next);
{
Printf (" % c % d % d % s ", p - & gt; Num, p - & gt; The name, p - & gt; Sex, p - & gt; The age);
}
}
Stu, struct student * del (struct student * int n)
{
Struct student * p, * the head;
For (p=stu, head=p; P!=NULL; P=p - & gt; Next)
{
If (p - & gt; Age==n)
{
If (p==head)
{
The head=p - & gt; Next;
}
Else if (p - & gt; Next==NULL)
{
(p - 1) - & gt; Next=NULL;
}
The else
{
(p - 1) - & gt; Next=p + 1;
}
}
}
return head;
}
Int main ()
{
int n;
Struct student stu [3].
Printf (" please enter student id name gender age in turn: \ n ");
Input (stu);
Printf (" please enter an age: \ n ");
The scanf (" % d ", & amp; n);
Print (del (stu, n));
}




This is the normal operation of the code
Then I will del function of p=p - & gt; After the next p++ instead, display an error,
Qaq o help bosses is this why

CodePudding user response:

The code is blocked, I resend

CodePudding user response:

# define _CRT_SECURE_NO_WARNINGS
# include
# define N 3
Struct student
{
int num;
Char name [50].
Char sex;
int age;
Struct student * next;
};
Void input (struct student * stu)
{
Struct student * p;
int i=0;
For (p=stu. P & lt; Stu + N. P++ i++)
{
Printf (" % d: ", I + 1);
The scanf (" % d % s % c % d ", & amp; P - & gt; Num, p - & gt; The name, & amp; P - & gt; Sex, & amp; P - & gt; The age);
I==N - 1? (stu [I] next=NULL) : (stu [I] next=& amp; Stu [I + 1));
}
}
Void print (struct student * stu)
{
Struct student * p;
For (p=stu. P - & gt; Next!=NULL; P=p - & gt; Next);
{
Printf (" % c % d % d % s ", p - & gt; Num, p - & gt; The name, p - & gt; Sex, p - & gt; The age);
}
}
Stu, struct student * del (struct student * int n)
{
Struct student * p, * the head;
For (p=stu, head=p; P!=NULL; P=p - & gt; Next)
{
If (p - & gt; Age==n)
{
If (p==head)
{
The head=p - & gt; Next;
}
Else if (p - & gt; Next==NULL)
{
(p - 1) - & gt; Next=NULL;
}
The else
{
(p - 1) - & gt; Next=p + 1;
}
}
}
return head;
}
Int main ()
{
int n;
Struct student stu [3].
Printf (" please enter student id name gender age in turn: \ n ");
Input (stu);
Printf (" please enter an age: \ n ");
The scanf (" % d ", & amp; n);
Print (del (stu, n));
}
  • Related