Solution: For the initialization of the linked list of leading nodes-Linux general technology-Linux programming and kernel information, see the following for details. The code is as follows:
Student management information
STU: Student Information Structure
The problem lies in the initialization part.
CODE: # define LEN sizeof (struct stu_info)
Typedef struct stu_info { Char name [20]; Long num; Float math_score; Float C_score; Float Eng_score; Struct stu_info * next; } STU;
STU * Stu_list_Init (STU * L) // initialize the linked list // There is a problem !!!!!!!!!!!!!! Why does it need a return value to run correctly? { STU * p; P = L; P = (STU *) malloc (LEN ); If (p = NULL) { Puts ("application space failed! "); Exit (0 ); } P-> next = NULL; Return L; }
Void Creat_list (STU * L) // Create a linked list { STU * tail, * p; Tail = L; Puts ("Input students info :"); While (1) { P = (STU *) malloc (LEN ); If (p = NULL) { Puts ("application space failed! "); Exit (0 ); } Printf ("\ t \ tname :"); Scanf ("% s", p-> name );
If (strncmp (p-> name, "end", 3) = 0) { Free (p ); Break; } Printf ("\ t \ tnumber :"); Scanf ("% ld", & p-> num ); Printf ("\ t \ tmath :"); Scanf ("% f", & p-> math_score ); Printf ("\ t \ tC :"); Scanf ("% f", & p-> C_score ); Printf ("\ t \ tEng :"); Scanf ("% f", & p-> Eng_score );
P-> next = NULL; Tail-> next = p; Tail = p; } Tail-> next = NULL; Fflush (NULL ); } Int main () { Struct stu_info * stu; Stu = Stu_list_Init (stu ); Creat_list (stu ); Return 0; } |