A simple information management system for students using linked lists

Source: Internet
Author: User

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct STUDENT
{
int id;
Char name[20];
int age;
char sex;
Char birthday[20];
Char address[20];
Char phone[15];
Char email[30];
struct student *next;
}student;

Student *head = NULL;
int length;
void Create ()
{
Student *p1,*p2;
length = 0;
P1 = (student *) malloc (sizeof (student));
P1->id =-1;
if (head = = NULL)
{
head = p1;
}
printf ("Please enter student's number, name, age, gender, date of birth, address, telephone, e-mail: \ n");
while (1)
{
P2 = (student *) malloc (sizeof (student));
scanf ("%d%s%d%c%s%s%s%s",&p2->id,p2->name,&p2->age,&p2->sex,&p2->birthday,& P2->address,p2->phone,p2->email);
if (P2->id = = 0)
{
printf ("Linked list creation complete!") \ n ");
Break
}
length + +;
P1->next = p2;
P2->next = NULL;
P1 = p1->next;
}
return;
}

void Loadstudentinfromfile ()
{
Student *p,*q;
int C;
File* F;
f = fopen ("Input.txt", "RB");
if (f = = NULL)
{
return;
}
Fseek (F,0,seek_set);
p = (student *) malloc (sizeof (student));
P->next = NULL;
head = p;
while (!feof (f))
{
c = fgetc (f);
if (c! =-1)
{
Fseek (f,-1,seek_cur);
}
Else
{
return;
}
Q = (student *) malloc (sizeof (student));
FSCANF (F, "%d", &q->id);
FSCANF (F, "%s", q->name);
FSCANF (F, "%d", &q->age);
FSCANF (F, "%c", &q->sex);
FSCANF (F, "%s", Q->birthday);
FSCANF (F, "%s", q->address);
FSCANF (F, "%s", Q->phone);
FSCANF (F, "%s", Q->email);
Q->next = NULL;
P->next = q;
p = p->next;
Length ++;//chain table Lengths
}
}

void Modifystudentinfo ()
{
Student *p = head->next;
int num;
printf ("Please enter the student number to be modified:");
scanf ("%d", &num);
while (P! = NULL)
{
if (p->id = = num)
{
printf ("Prior to modification, student number%d is as follows: \ n", num);
printf ("%d%s%d%c%s%s%s%s", p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p- >email);
printf ("Please enter the student's new phone:");
GetChar ();
Gets (P->phone);
printf ("Please enter the student's new address:");
Gets (p->address);
printf ("Modified, student ID%d is as follows: \ n", num);
printf ("%d%s%d%c%s%s%s%s", &p->id,p->name,&p->age,p->sex,p->birthday,p->address,p- >phone,p->email);
return;
}
p = p->next;
}
if (p = = NULL)
{
printf ("The school number does not exist!") \ n ");
return;
}
}
void display ()
{
Student *p = head->next;
printf ("All student information in the linked list is as follows: \ n");
while (P! = NULL)
{
printf ("%d%s%d%c%s%s%s%s", p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p- >email);
printf ("\ n");
p = p->next;
}
return;
}

Void Search ()
{
int num,x;
Char name[20];
Student *p = head->next;
printf ("Please select Query method: \ n");
printf ("1, Inquiry \t2 by number, search by name \ n");
scanf ("%d", &x);
if (x = = 1)
{
printf ("Student number to find is:");
scanf ("%d", num);
while (P! = NULL)
{
if (p->id = = num)
{
printf ("Student information%d" is as follows: \ n ", num);
printf ("%d%s%d%c%s%s%s%s", p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p- >email);
return;
}
P = p->next;
}
if (p = = NULL)
{
printf ("No This record! \ n ");
}
}
Else if (x = = 2)
{
printf ("The student name to look for is:");
GetChar ();
gets (name);
P = head->next;
while (P! = NULL)
{
if (strcmp (p->name,name) = = 0)
{
printf ("Student name%s student information is as follows: \ n", name);
printf ("%d%s%d%c%s%s%s%s", p->id,p->name,p->age,p->sex,p->birthday,p->address,p->phone,p- >email);
return;
}
P = p->next;
}
if (p = = NULL)
{
printf ("No This record! \ n ");
}
}
return;
}

void Insert ()
{
int num,i;
Student *p,*q;
p = head;

printf ("Please enter the location you want to insert:");
scanf ("%d", &num);
if (num > Length)
{
printf ("Cannot find the inserted location \ n");
return;
}
Else
{
printf ("Please enter the information for the student you want to insert: \ n");
Q = (student *) malloc (sizeof (student));
scanf ("%d%s%d%c%s%s%s%s", &q->id,q->name,&q->age,&q->sex,q->birthday,q->address, Q->phone,q->email);
while (P! = NULL)
{
if (P->id = = Q->id)
{
printf ("The school number already exists and cannot be inserted!") \ n ");
return;
}
p = p->next;
}
p = head;
for (i=0; i<num; ++i)
{
p = p->next;
}
Q->next = p->next;
P->next = q;
length + +;
printf ("Insert succeeded! \ n ");
return;
}
}

void Delete ()
{
int num;
Student *p,*q;
Q = head;
p = head->next;
printf ("Please enter the student number for deletion: \ n");
scanf ("%d", &num);

while (P! = NULL)
{
if (p->id = = num)
{
Q->next = p->next;
Free (p);
Length--;
printf ("Delete succeeded! \ n ");
return;
}
p = p->next;
Q = q->next;
}
if (p = = NULL)
{
printf ("Could not find the number to delete!") \ n ");
return;
}
}

void menu ()
{
printf ("___________________________________________________\n");
printf ("| Student information Management System |\n");
printf ("|, exit System |\n");
printf ("|\n", enter student information);
printf ("|\n, establish linked list");
printf ("|3, display linked list |\n");
printf ("|4, find an element in the list |\n");
printf ("|5, deleting the node of the specified study number in the list |\n");
printf ("|6, insert a new node in the specified position |\n");
printf ("|7, revise student information |\n");
printf ("__________________________________________________\n");
return;
}

int main (void)
{
int A;
menu ();
while (1)
{
printf ("Please enter the appropriate function:");
scanf ("%d", &a);
Switch (a)
{
Case 0:
return 0;
Case 1:
Loadstudentinfromfile ();
menu ();
break;
Case 2:
Create ();
menu ();
break;
Case 3:
if (head)
{
display ();
menu ();
}
Else
{
printf ("The list is empty, please build the list first!") \ n ");
Menu ();
}
Break;
Case 4:
if (head)
{
Search ();
menu ();
}
Else
{
printf ("The list is empty, please build the list first!") \ n ");
Menu ();
}
Break;
Case 5:
if (head)
{
Delete ();
menu ();
}
Else
{
printf ("The list is empty, please build the list first!") \ n ");
Menu ();
}
Break;
Case 6:
if (head)
{
Insert ();
menu ();
}
Else
{
printf ("The list is empty, please build the list first!") \ n ");
Menu ();
}
Break;
Case 7:
if (head)
{
Modifystudentinfo ();
menu ();
}
Else
{
printf ("The list is empty, please build the list first!") \ n ");
Menu ();
}
Break;
Default:
break;
}
}
System ("pause");
return 0;
}

Using linked lists to implement a simple student information management system

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.