C language-simple student information management (memory linked list exercises)

Source: Internet
Author: User

When I first learned C, I just learned it as the basis of programming. Now I will look back and find that if I want to program it, not to do the application, it's still cool to C. (It does not mean that C cannot be used as an application. On the contrary, some applications only support C, but B/S is easy to use Java \ C # \ PHP .)

A simple student information management, because it was edited using vim, Chinese annotations were not added. There are three main functions, main ()
New_stud () and listall () can understand the structure and functions at a glance.

 

 

C
# Include < Stdio. h >
# Include < Stdlib. h >

StructStud
{

LongNum;

CharName [20];

StructStud*Next;
};

Void New_stud ();
Void Listall ();
Struct Stud * Head, * Cur, * Newp;
Int Main ( Char Argc, Char ** Argv)
{
Char Ch;
Int Isclose = 0 ;
Head = NULL;
While ( ! Isclose)
{
Printf ( " \ N type 'E' or 'e' to enter new student, " );
Printf ( " \ N type 'L' or 'l' to list all students: " );
Ch = Getchar ();
Getchar ();
Switch (CH)
{
Case   ' E ' :
Case   ' E ' : New_stud (); Break ;
Case   ' L ' :
Case   ' L ' : Listall (); Break ;
Default : Isclose = 1 ;
};
}

Return 0;
}

Void New_stud ()
{
Char Numstr [ 20 ];
Newp = ( Struct Stud * ) Malloc ( Sizeof ( Struct Stud ));
If (Head = Null)
{
Head = Newp;
}
Else
{
Cur = Head;
While (Cur -> Next ! = Null)
{
Cur = Cur -> Next;
}
Cur -> Next = Newp;
}
Cur = Newp;
Printf ( " \ N enter no .: " );
Gets (numstr );
Cur -> Num = Atol (numstr );
Printf ( " \ N enter Name: " );
Gets (cur -> Name );
Cur -> Next = NULL;
}

Void Listall ()
{
Int I = 0 ;
If (Head = Null)
{
Printf ( " \ N no student! " );
Return ;
}
Cur = Head;
Do
{
Printf ( " \ N ================================== " );
Printf ( " \ N num: % LD " , Cur -> Num );
Printf ( " \ N name: % s " , Cur -> Name );
Printf ( " \ N ------------------------ " );
Cur = Cur -> Next;
}
While (Cur ! = Null );
}

 

 

 

Note: Long atol (const char * nptr) will scan the nptr parameter string, skip the leading space character, and start conversion only when a number or positive or negative sign is encountered, the conversion ends only when a non-number or string ends ('') and the result is returned. Returns the number of converted long integers.

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.