Something you write yourself!

Source: Internet
Author: User

/*************************************** ***********************/
/* Address Book Management System */
/* Production: zky */
/* Time: 09/10 /***/
/*************************************** ***********************/
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
Typedef struct student/* student information structure */
{
Int ID;
Char name [20];
Char sex [5];
Int age;
Char telephone [20];
Int roomphone;
Char homeadress [20];
} St;
Typedef struct date
{
Struct student Stu;
Struct date * next;
} Lnode, * linklist;
Linklist start_list (int n)/* Create */
{
Void PRI (linklist L );
Linklist L, K, S;
Struct student X;
Int I;
L = (linklist) malloc (sizeof (lnode ));
L-> next = NULL;
For (I = 1; I <= N; I ++)
{
Printf ("/T item % d", I );
S = (linklist) malloc (sizeof (lnode ));
Printf ("/N 7 items in total, input one by one, please note the character type/n please enter the student ID (INT ):");
Scanf ("% d", & X. ID );
Printf ("enter your name (char ):");
Scanf ("% s", & X. Name );
Printf ("Enter the gender (char ):");
Scanf ("% s", & X. Sex );
Printf ("Enter age (INT ):");
Scanf ("% d", & X. Age );
Printf ("Enter the mobile phone number (char ):");
Scanf ("% s", & X. Telephone );
Printf ("Enter the Dormitory number (INT ):");
Scanf ("% d", & X. roomphone );
Printf ("Enter the address (char ):");
Scanf ("% s", & X. homeadress );
S-> Stu = X;
S-> next = L-> next;
L-> next = s;
}
PRI (L );
Return L;

}

Linklist list_search (linklist L, int I)/* search and locate */
{
Linklist P = L;
Int J = 0;
While (p-> next! = NULL & J <I)
{
P = p-> next;
J ++;
}
If (j = I)
Return P;
Else
Return NULL;
}
Linklist term_search (linklist L, int I)/* condition (student ID) query */
{
 
}
Linklist swapinset_link (linklist L, int I, St R)/* Insert/replace */
{
Int J;
Linklist P, S;
P = list_search (L, I );
S = (linklist) malloc (sizeof (lnode ));
S-> Stu = R;
S-> next = p-> next;
P-> next = s;
Return P;
}
Linklist del_list (linklist L, int N)/* Delete */
{
Linklist P, S;
P = list_search (L, N );
If (P = NULL)
{
Printf ("*****! Error! */N ");
}
Else
{
If (p-> next = NULL)
{
Printf ("****** null, no element ******/N ");
}
Else
{
S = p-> next;
P-> next = s-> next;
Free (s );
}

}
Return P;
}
Void PRI (linklist L)/* output function */
{
Linklist S;
Int I = 1;
S = L-> next;
Printf ("the member information in the address book is :");
Printf ("/n/T %-7 S % 10 S % 8 S % 10 S % 8 S % 15 S % 10 s", "student ID", "name ", "gender", "Age", "Mobile Phone", "Dormitory number", "Home Address ");
While (s! = NULL)
{
Printf ("/n % d", I );
Printf ("/T %-7D % 10 S % 8 S % 10d % 8 S % 15d % 5 S/N", S-> Stu. ID, S-> Stu. name, S-> Stu. sex, S-> Stu. age, S-> Stu. telephone, S-> Stu. roomphone, S-> Stu. homeadress );
S = s-> next;
I ++;
}
 
}
Int main ()
{
Printf ("********************* welcome to use the address book management system *********** ***************");
Int D, I;
Int flg;
Linklist P, S;
P = (linklist) malloc (sizeof (lnode ));
Printf ("/N, enter the number of created lists :");
Scanf ("% d", & D );
P = start_list (d );
Loop: printf ("/n ***** ① insert ② Delete *****");
Printf ("/n ***** ③ replace ④ find *****");
Printf ("/n ******* ⑤ exit ***********");
Printf ("/N, enter the operation you want to perform. Enter the number :");
Scanf ("% d", & D );
If (D = 1)
{
Struct student N;
Printf ("/n insert element position: (a total of seven input items one by one, note the input character type, the input error is at your own risk )");
Scanf ("% d", & D );
Printf ("/N input information :");
Printf ("/n student ID (integer ):");
Scanf ("% d", & N. ID );
Printf ("Name (string ):");
Scanf ("% s", & N. Name );
Printf ("Gender (string ):");
Scanf ("% s", & N. Sex );
Printf ("Age (integer ):");
Scanf ("% d", & N. Age );
Printf ("mobile phone number: (string )");
Scanf ("% s", & N. Telephone );
Printf ("Dormitory number: (integer )");
Scanf ("% d", & N. roomphone );
Printf ("Address: (string )");
Scanf ("% s", & N. homeadress );
S = swapinset_link (p, d, n );
PRI (P );
Goto
Loop;

}
If (D = 2)
{
Printf ("/N, enter the elements to be deleted :");
Scanf ("% d", & D );
S = del_list (p, D-1 );
PRI (P );
P = s;
Goto
Loop;
}
If (D = 3)
{
Struct student X;
Printf ("Enter the location of the element to be replaced :");
Scanf ("% d", & D );
Printf ("Enter New Element Information:/N ");
Printf ("/n student ID (INT ):");
Scanf ("% d", & X. ID );
Printf ("Name (char ):");
Scanf ("% s", & X. Name );
Printf ("Gender (char ):");
Scanf ("% s", & X. Sex );
Printf ("Age (INT ):");
Scanf ("% d", & X. Age );
Printf ("mobile phone number (char ):");
Scanf ("% s", & X. Telephone );
Printf ("Dormitory number (INT ):");
Scanf ("% d", & X. roomphone );
Printf ("address (char ):");
Scanf ("% s", & X. homeadress );
P = swapinset_link (p, D, X );
PRI (P );
Goto
Loop;
}
If (D = 4)
{
Printf ("Enter the serial number of the element to be searched :");
Scanf ("% d", & D );
S = list_search (p, d );
If (P! = NULL)
{
Printf ("/n %-5 S % 10 S % 10 S % 10 S % 15 S % 15 S % 10 s", "student ID", "name ", "gender", "Age", "Mobile Phone", "Dormitory number", "Home Address ");
Printf ("/n %-5d % 10 S % 10 S % 10d % 15 S % 15d % 5 S/N", S-> Stu. ID, S-> Stu. name, S-> Stu. sex, S-> Stu. age, S-> Stu. telephone, S-> Stu. roomphone, S-> Stu. homeadress );
}
If (P = NULL)
{
Printf ("/n/T ******************");
Printf ("/n/T **!! This element is not found !! **");
Printf ("/n/T *******************");
}
Goto
Loop;
}
If (D = 5)
{
Exit (0 );
}
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.