Solution: Questions about initialization of the linked list of the leading node

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.