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.