Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include <stdlib.h>
- typedef struct Node
- {
- char id[20];
- char phone[20];
- char dept[20];
- char bg[5];
- char adress[20];
- char name[20];
- struct Node *next;
- } node;
- void insert_after(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
- {
- while(p->next != NULL)
- {
- p = p->next;
- }
- p->next = (node *)malloc(sizeof(node));
- strcpy(p->next->name,name);
- strcpy(p->next->id,id);
- strcpy(p->next->dept,dept);
- strcpy(p->next->bg,bg);
- strcpy(p->next->phone,cont);
- p->next->next = NULL;
- }
- void insert_first(node *p,char name[20], char id[20], char dept[20], char bg[5], char cont[20])
- {
- node *temp;
- temp = (node *)malloc(sizeof(node));
- strcpy(temp->name,name);
- strcpy(temp->id,id);
- strcpy(temp->dept,dept);
- strcpy(temp->bg,bg);
- strcpy(temp->phone,cont);
- temp->next = p->next;
- p->next = temp;
- }
- void edit_data(node *p,char id[])
- {
- int n,ct=0;
- char name1[20];
- char id1[20];
- char dept1[20];
- char bg1[20];
- char phone1[20];
- //node *temp = search(p,id);
- p = p->next;
- while(p != NULL)
- {
- if(strcmp(p->id,id) == 0)
- {
- printf("\n---------------------------------------------------------------\n");
- printf(" ****Student's Data To Edit**** ");
- printf("\n---------------------------------------------------------------\n");
- printf("1.Student name : %s\n", p->name);
- printf("2.Student ID : %s\n", p->id);
- printf("3.Student Department : %s\n", p->dept);
- printf("4.Student Blood group: %s\n", p->bg);
- printf("5.Student Contact : %s\n\n",p->phone);
- printf("Select your option to Edit: ");
- scanf("%d",&n);
- if(n == 1)
- {
- printf("Enter the name: ");
- scanf(" %[^\n]s",name1);
- strcpy(p->name,name1);
- }
- else if(n == 2)
- {
- printf("Enter the ID: ");
- scanf(" %s",id1);
- strcpy(p->id,id1);
- }
- else if(n == 3)
- {
- printf("Enter the Department: ");
- scanf("%s",dept1);
- strcpy(p->dept,dept1);
- }
- else if(n == 4)
- {
- printf("Enter the Blood Group: ");
- scanf("%s",bg1);
- strcpy(p->bg,bg1);
- }
- else if(n == 5)
- {
- printf("Enter the Contact: ");
- scanf("%s",phone1);
- strcpy(p->phone,phone1);
- }
- else
- {
- printf("\nError Selection!!\n");
- }
- }
- ct++;
- p = p -> next;
- }
- if(ct == 0)
- printf("\nElement not Found!\n");
- }
- int search(node *p, char id[20])
- {
- p = p->next;
- while(p != NULL)
- {
- if(strcmp(p->id,id) == 0)
- {
- printf("\n---------------------------------------------------------------\n");
- printf(" ****Displaying Searched Information**** ");
- printf("\n---------------------------------------------------------------\n");
- printf("Student name : %s\n", p->name);
- printf("Student ID : %s\n", p->id);
- printf("Student Department : %s\n", p->dept);
- printf("Student Blood group: %s\n", p->bg);
- printf("Student Contact : %s\n\n",p->phone);
- return;
- }
- p = p -> next;
- }
- printf("Sorry!Element not found.\n");
- return;
- }
- void blood_grp(node *p, char bg[5])
- {
- int ct=0;
- p = p->next;
- printf("\n---------------------------------------------------------------\n");
- printf(" ****Information of Desired Blood Group**** ");
- printf("\n---------------------------------------------------------------\n");
- while(p != NULL)
- {
- if(strcmp(p->bg,bg)==0)
- {
- ct++;
- printf("\nStudent Name : %s\n",p->name);
- printf("Blood Group : %s\n",p->bg);
- printf("Contact number: %s\n",p->phone);
- }
- p = p->next;
- }
- if(ct == 0)
- printf("\nNot found\n");
- }
- void dept_search(node *p, char dept[20])
- {
- int ct=0;
- p = p->next;
- printf("\n---------------------------------------------------------------\n");
- printf(" ****Department Wise Student Information**** ");
- printf("\n---------------------------------------------------------------\n");
- while(p != NULL)
- {
- if(strcmp(p->dept,dept)==0)
- {
- ct++;
- printf("Student name : %s\n", p->name);
- printf("Student ID : %s\n", p->id);
- printf("Student Department : %s\n", p->dept);
- printf("Student Blood group: %s\n", p->bg);
- printf("Student Contact : %s\n\n", p->phone);
- }
- p = p->next;
- }
- if(ct == 0)
- printf("\nNot found\n");
- }
- void delete(node *p, char id[20])
- {
- int ct=0;
- node *temp;
- while(p->next != NULL)
- {
- if(strcmp(p->next->id,id) == 0)
- {
- ct++;
- temp = p->next;
- p->next = temp->next;
- free(temp);
- return 0;
- }
- p = p->next;
- }
- if(ct == 0)
- {
- printf("Element Not Found!!\n");
- }
- }
- void display(node *p)
- {
- while(p -> next != NULL)
- {
- printf("Student name : %s\n", p->next->name);
- printf("Student ID : %s\n", p->next->id);
- printf("Student Department : %s\n", p->next->dept);
- printf("Student Blood group: %s\n", p->next->bg);
- printf("Student Contact : %s\n\n", p->next->phone);
- //printf("Student name: %s\n", p->next->name);
- p = p->next;
- }
- }
- void check_id(node *p,char id[])
- {
- while(p->next != NULL)
- {
- if(strcmp(p->next->id,id)==0)
- {
- printf("\nThis ID Already exists!\n");
- printf("Enter a new ID please! :- ");
- scanf("%s",id);
- }
- p = p->next;
- }
- }
- int main()
- {
- system("color f0");
- int s;
- char q;
- char name[20];
- char id[20];
- char dept[20];
- char bg[20];
- char phone[20];
- node *start = (node *)malloc(sizeof(node));
- start -> next = NULL;
- while(1)
- {
- printf("\n----------------------------------------------------------------------------\n");
- printf(" Welcome to Student Database Management System" );
- printf("\n----------------------------------------------------------------------------\n");
- printf("\tLog in as:\n");
- printf(" \n\t\t 1. ADMIN \n\n\t\t 0. EXIT");
- printf("\n----------------------------------------------------------------------------\n");
- printf(" " );
- printf("\n----------------------------------------------------------------------------\n");
- printf("\n\tEnter Choice:\t\t");
- int choice;
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- while(1)
- {
- printf("\n\n1. Insert Student Data\n");
- printf("2. Delete Student Data\n");
- printf("3. Display\n");
- printf("4. Search\n");
- printf("5. Insert at first\n");
- printf("6. Edit Student information\n");
- printf("7. Search Blood Group\n");
- printf("8. Search Department\n");
- printf("9. Exit\n");
- printf("\nEnter your choice: ");
- scanf(" %c",&q);
- switch(q)
- {
- case '1':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n---------------------------------------------------------------\n");
- printf(" Enter Student information ");
- printf("\n---------------------------------------------------------------\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter ID: ");
- scanf("%s", id);
- check_id(start,id);
- printf("Enter Department: ");
- scanf(" %s", dept);
- printf("Enter Blood Group: ");
- scanf("%s", bg);
- printf("Enter contact: ");
- scanf("%s", phone);
- insert_after(start,name,id,dept,bg,phone);
- }
- break;
- case '2':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("Enter a Student's ID to Delete data: ");
- scanf("%s", id);
- delete(start,id);
- }
- break;
- case '3':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n---------------------------------------------------------------\n");
- printf(" ****Student's personal information**** ");
- printf("\n---------------------------------------------------------------\n");
- display(start);
- }
- break;
- case '4':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("Enter the ID: ");
- scanf("%s",id);
- search(start,id);
- }
- break;
- case '5':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\n\nEnter student information\n\n");
- printf("Enter name: ");
- scanf(" %[^\n]s", name);
- printf("Enter ID: ");
- scanf("%s", id);
- printf("Enter Department: ");
- scanf(" %[^\n]s", dept);
- printf("Enter Blood Group: ");
- scanf("%s", bg);
- printf("Enter contact: ");
- scanf("%s", phone);
- insert_first(start,name,id,dept,bg,phone);
- }
- break;
- case '6':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\nEnter the ID to Edit data: ");
- scanf("%s",id);
- edit_data(start,id);
- }
- break;
- case '7':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\nEnter the desired Blood Group: ");
- scanf("%s",bg);
- blood_grp(start,bg);
- }
- break;
- case '8':
- system("CLS");
- printf("\nIf your want to EXIT press '0' else press any key\n");
- scanf("%d",&s);
- if(s == 0)
- break;
- else
- {
- printf("\nEnter Department Name: ");
- scanf("%s",dept);
- dept_search(start,dept);
- }
- break;
- case '0':
- exit(0);
- default:
- system("CLS");
- printf("Invalid choice.Try again!\n");
- break;
- }
- }
- case 0:
- exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement