Home > Back-end >  Great god save of code execution, finished to input the name directly after the program, feel is a s
Great god save of code execution, finished to input the name directly after the program, feel is a s

Time:12-03

# include
# include
# define MAX 100
# define NULL 0
Typedef struct stu//student information (list)
{
char name[20];
int num;
Int place;
Float score;
} stu.
Typedef struct lnode {
Struct stu * data;
Struct lnode * next;
} lnode * linklist;
Int n=0;
Void menu ();
Void the add (linklist);
//void display (linklist);

Void main () {
The menu ();
}


Void menu () {
Linklist=l (linklist) malloc (sizeof (lnode));
L - & gt; Next=NULL;
int a;
Printf (" * * * * * * * * * * please choose corresponding function * * * * * * * * * * \ n \ n ");
Printf (" | | 1, enter the student information \ n ");
Printf (" | | 2, according to all the students information \ n ");
Printf (" | | 3, find students information \ n ");
Printf (" | | 4, students to find a position information \ n ");
Printf (" | | 5, find students information \ n ");
Printf (" | | 6, delete student information \ n ");
Printf (" | | 7, statistical students number \ n ");
The scanf (" % d ", & amp; A);
If (a==1) add (l);
//if (a==2) display (l);
}


Void the add (linklist l) {
Int s;
Linklist p;
Printf (" please input to input the number of students: ");
The scanf (" % d ", & amp; S);
for(int i=1; i<=s; I++) {
P=(linklist) malloc (sizeof (lnode));
Printf (" \ n please enter the first % d a student's name: ", I);
The scanf (" % s ", & amp; P - & gt; Data - & gt; Name);
Printf (" \ n please enter the first % d a student's student id: ", I);
The scanf (" % d ", & amp; P - & gt; Data - & gt; num);
Printf (" \ n please enter the first % d student achievement: ", I);
The scanf (" % f ", & amp; P - & gt; Data - & gt; Score);
n++;
P - & gt; Data - & gt; Place=n;
L - & gt; Next=p;
P - & gt; Next=NULL;
}
Printf (" press 1 key to return to menu ");
The scanf (" % d ", & amp; S);
If (s==1) menu ();
}

CodePudding user response:

L - & gt; Next=p;
P - & gt; Next=NULL;
If l is the head pointer, generally want to define a pointer, pointer to the first, and use it to operation, the head pointer generally does not move, because it is the beginning of the list, it still can't find the end,
  • Related