# Include "stdio. h"
# Include "string. h"
# Include "stdlib. h"
# Define N 3
# Define increase 4
# Define NULL 0
Typedef struct stud
{
Char name [15];
Int age;
Float score;
Struct stud * next;
} L;/* define the table type */
L * p, * that, * othernew, * x, * you, * head;
L * enter_record ()/* Add record */
{
Int n, I = 0;
Float m;
L * new;
Head = new = (L *) malloc (N * sizeof (L ));
If (! New)
{
Printf ("failure for applying room! N ");
Exit (0 );
}
Else
{
P = new;
While (I <N)
{
I ++;
Printf ("please enter name :");
Fflush (stdin );
Gets (p-> name );
Printf ("n ");
Printf ("enter age :");
Fflush (stdin );
Scanf ("% d", & n );
Printf ("n ");
P-> age = n;
Printf ("enter the score :");
Fflush (stdin );
Scanf ("% f", & m );
P-> score = m;
P = p-> next;
}
}
Return head;
}
L * show_record ()/* Display Record */
{
Int c = 1;
L * this;
Printf ("the records are: n ");
This = head;
While (this-> next! = NULL)
{
Printf ("the % d th is: n ");
Printf ("the name is: % sn", this-> name );
Printf ("the age is: % dn", this-> age );
Printf ("the score is: % fn ");
This = this-> next;
C ++;
}
Printf ("the number of records is: % d", c );
Return head;
}
L * delete_record ()/* delete record */
{
Int d;
Printf ("which one record do you want to delete? Number :");
Fflush (stdin );
Scanf ("% d", & d );
Printf ("n ");
If (d> N-1 | d <0)
{
Printf ("error due to the wrong input! N ");
Exit (0 );
}
Else
{
Int e = 1;
That = head;
While (that-> next! = NULL & e <d)
{
That = that-> next;
E ++;
}
That-> next = that-> next;
Free (that-> next );
Printf ("the record has been deleted! N ");
}
Return head;
}
L * insert_record ()/* Add a new record */
{
Int y;
Printf ("where will you insert the new record? Number :");
Fflush (stdin );
Scanf ("% d", & y );
Printf ("n ");
If (y> = 1 & y <= N)
{
Int z = 1, g, h;
X = head;
While (x-> next! = NULL & z <= N)
{
Z ++;
X = x-> next;
}
Othernew = (L *) malloc (sizeof (L ));
X-> next = othernew;
Othernew = x-> next;
Printf ("please input the name new record: % sn", othernew-> name );
Scanf ("% d", & g );
Printf ("enter the age: % dn", g );
Scanf ("% d ",
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.