C language for personal address book management system
- 2020-06-23 01:16:59
- OfStack
How to make a simple personal address book management system in c language? This must be a big problem for every student learning c. How do you store and access data elements of different data types? Using a structure can easily solve this problem!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
struct stu // The first 1 Section: Declare structure types struct stu
{
char name[100];// The name is of string type
int xh;// Student id for plastic
int grade;// grade
char cel[15];// Mobile phone
char tel[50];// The phone
char mail[50];// mail
char add[100];// The address is of string type
char post[15];// Zip code
struct stu *next;// Using Pointers to process linked lists, next Is a pointer variable that points to a structure variable
};
struct stu *charu(struct stu *head,struct stu *q)// The first 2 Part: Insert function (insert new node )
{
struct stu *p;
for(p=head;p->next!=NULL;p=p->next);//for( make p Point to head; when p Is an empty file ;p Point to the 1 A node)
p->next=q;
q->next=NULL;
return head;
}
void search(struct stu *head) // The first 3 Part: Find node and output
{
struct stu *p;
int a;// Look up the student's student number
if(head->next==NULL)// The result printed when the header file is empty is " The address book is empty "
printf("********************************** The address book is empty !!!*********************************\n\n\n");
else// When the header file is not empty, start searching for student information
{
printf("\t Input to query student id :");
scanf("%d",&a);
for(p=head->next;p->next!=NULL;p=p->next)//for( make p Point to head; when p Is an empty file ;p Point to the 1 A node)
{
if(p->xh==a) // If the input number is the same as one, output the following.
{
printf(" The student information to find is :\n");
printf(" Taken the name: ");puts(p->name);
printf("\t Student id : ");printf("%d",p->xh);
printf("\t Grade: ");printf("%d\n",p->grade);
printf("\t Mobile phone: ");puts(p->cel);
printf("\t Telephone: ");puts(p->tel);
printf("\t Email address: ");puts(p->mail);
printf("\t address ");puts(p->add);
printf("\t Zip code: ");puts(p->post);
printf("\t Find success !!!");
printf("\n\n\n");
break;
}
}
if(p->xh==a)
{
printf(" The student information to find is :\n");
printf(" Taken the name: ");puts(p->name);
printf("\t Grade: ");printf("%d\n",p->grade);
printf("\t Mobile phone: ");puts(p->cel);
printf("\t Telephone: ");puts(p->tel);
printf("\t Email address: ");puts(p->mail);
printf("\t address ");puts(p->add);
printf("\t Zip code: ");puts(p->post);
printf("\t Find success !!!");
printf("\n\n\n");
}
else printf("no people have found!!!\n");// If not, the output is not found
}
}
struct stu *del(struct stu *head) // The first 4 Section: Delete node
{
struct stu *p,*q;
int a;// To delete a student's student number
if(head->next==NULL)// If the header file is empty, the output address book is empty
printf("********************************** The address book is empty !!!*********************************\n\n\n");
else
{
printf("\t Enter the student number to delete :");
scanf("%d",&a);
for(p=head,q=p->next;q->xh!=a&&q->next!=NULL;)
{
p=p->next;
q=p->next;
}
if(q->xh==a)
{
p->next=q->next;
free(q);// The release of q, That's deleting q In this case, delete q( Student id for a)
printf(" Delete the success !!!\n");
}
else printf("no people have found!!!");// If not, the output is not found
}
return head;// Return to header file
}
struct stu *change(struct stu *head) // The first 5 Section: Modify node content
{
int b,a,c;
struct stu *p;
if(head->next==NULL)// If the header file is empty, the output address book is empty
printf("********************************** The address book is empty !!!*********************************\n\n\n");
else
{
printf(" Enter the student id to change :");
scanf("%d",&a);
for(p=head->next;p!=NULL;p=p->next)
{
start:printf(" What do you want to modify ?\n");
printf("\t\t\t 1: Modify the name \n");
printf("\t\t\t 2: Modify the student id \n");
printf("\t\t\t 3: Modify the grade \n");
printf("\t\t\t 4: Mobile phone \n");
printf("\t\t\t 5: The phone \n");
printf("\t\t\t 6: mail \n");
printf("\t\t\t 7: address \n");
printf("\t\t\t 8: Zip code \n");
printf(" Please enter your choice: ");
scanf("%d",&b);
switch(b)// Find the student by the student number and then use it switch Statement to select the modification item, then use switch and goto Whether the statement implements a loop or not
{
case 1:
printf("\t Enter a new name :");
scanf("%s",p->name);break;
case 2:printf("\t Enter the new student number :");
scanf("%d",&p->xh);break;
case 3:
printf("\t Enter the new grade :");
scanf("%d",&p->grade);break;
case 4:
printf("\t Enter a new phone number :");
scanf("%s",p->cel);break;
case 5:
printf("\t Enter a new phone number :");
scanf("%s",p->tel);break;
case 6:
printf("\t Enter a new mailbox :");
scanf("%s",p->mail);break;
case 7:
printf("\t Enter a new address :");
scanf("%s",p->add);break;
case 8:
printf("\t Enter the new zip code ;");
scanf("%s",p->post);break;
default: printf(" Input operation error, please reinput :");
}
printf(" Modify the success !!!\n");
printf(" Do you want to modify other items? 1 Is: 2 : no \n");
printf(" Please enter your choice: ");
scanf("%d",&c);
switch(c) //goto Whether the statement implements a loop or not
{
case 1:goto start;
case 2:break;
}
}
}
return head; // Return to header file
}
void printall(struct stu *head) // The first 6 Part: Output all address book
{
struct stu *p=head->next;
while(1)
{
if(p==NULL)
{
printf("********************************** The address book is empty !!!*********************************\n\n\n");
break;
}
else if(p->next==NULL)
{
printf(" Taken the name: ");puts(p->name);
printf("\t Student number: ");printf("%d\n",p->xh);
printf("\t Grade: ");printf("%d\n",p->grade);
printf("\t Mobile phone: ");puts(p->cel);
printf("\t Telephone: ");puts(p->tel);
printf("\t Email address: ");puts(p->mail);
printf("\t Address: ");puts(p->add);
printf("\t Zip code: ");puts(p->post);
printf(" The output is successful !!!\n");
printf("\n\n\n");
break;
}
else
{
printf(" Taken the name: ");puts(p->name);
printf("\t Student number: ");printf("%d\n",p->xh);
printf("\t Grade: ");printf("%d\n",p->grade);
printf("\t Mobile phone: ");puts(p->cel);
printf("\t Telephone: ");puts(p->tel);
printf("\t Email address: ");puts(p->mail);
printf("\t Address: ");puts(p->add);
printf("\t Zip code: ");puts(p->post);
printf("\n");
p=p->next;
continue;
}
printf(" The output is successful !!!\n");
}
}
void sf(struct stu *head) // The first 8 Part: release node to exit the system
{
struct stu *p=head ;
printf(" Release of the list :\n");
while(p!=NULL)
{
head=head->next;
free(p);
p=head;
}
printf(" Release list successful !!!\n");
}
int main()// The first 9 Part: Main function framework
{
int cz;// The operator
struct stu *head,*q;
head=(struct stu*)malloc(sizeof(struct stu));// The dynamic linked list malloc
head->next=NULL;// make next Point to the 1 A node ,next Nodes do not put other node addresses
system("color 1e");// Modify the dos Front window background color , With the two 106 Base number representation
printf(" Class: Name: Student number: Design topic: Personal address book management system \n");
printf("\n********************************C Language course design ***********************************\n");
printf(" ******************* Personal address book management system *****************\n\n\n");
printf(" * 1: New address book *\n");
printf(" * 2: Delete address book *\n");
printf(" * 3: Modify address book *\n");
printf(" * 4: Enquiry Address book *\n");
printf(" * 5: Display all records *\n");
printf(" * 6: Release the list and end the program *\n");
printf(" *********************************************************\n");
start :printf(" Input operator 1-6:");//" Input operator 1-
scanf("%d",&cz);
switch(cz)//switch statements
{
case 1:
q=(struct stu *)malloc(sizeof(struct stu));
printf("\t Enter the name :");scanf("%s",q->name);
printf("\t Enter the student id :");scanf("%d",&q->xh);
printf("\t Input grade :");scanf("%d",&q->grade);
printf("\t Mobile phone no. :");scanf("%s",q->cel);
printf("\t The home phone :");scanf("%s",q->tel);
printf("\t Enter E-mail :");scanf("%s",q->mail);
printf("\t Address book address :");scanf("%s",&q->add);
printf("\t Enter zip code :");scanf("%s",&q->post);
charu(head,q);
printf(" Insert the success !!!\n");break;
case 2:// delete
head=del(head);break;
case 3:
change(head);break;// Modify student information
case 4:
search(head);break;// To find the node head
case 5:
printall(head);break; // Save the file
case 6: // Release node to exit the system
sf(head);
exit (0);
default: printf(" Input error , again "); // What doesn't fit " Input error , again "
}
goto start;// with goto Statement implements a loop operation
return 0;
}
For more information, please pay attention to the topic management System Development.