├── Library_Management_System.c └── README.md /Library_Management_System.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | struct book{ 9 | char name[30]; 10 | char author[30]; 11 | int id; 12 | struct book *next; 13 | }; 14 | 15 | struct student{ 16 | char name[30]; 17 | char email[20]; 18 | char book[20]; 19 | char a[30]; 20 | int id; 21 | struct student *next; 22 | }; 23 | 24 | struct book *start_lib=NULL; 25 | struct student *start=NULL; 26 | struct book *initialize_lib(struct book *); 27 | struct student *book_issue(struct student *); 28 | struct student *book_return(struct student *); 29 | struct book *diplay_lib(struct book *); 30 | struct book *delete_book(int); 31 | struct book *add_book(char [],char [],int); 32 | void display(struct student *); 33 | void greetings(); 34 | void main_menu(); 35 | 36 | int main(){ 37 | start_lib=initialize_lib(start_lib); 38 | greetings(); 39 | main_menu(); 40 | return 0; 41 | } 42 | 43 | void greetings(){ 44 | printf("\n\n"); 45 | printf("\t\t\t ****************************************\n"); 46 | printf("\t\t\t * *\n"); 47 | printf("\t\t\t * *\n"); 48 | printf("\t\t\t * ---------------------------- *\n"); 49 | printf("\t\t\t * WELCOME TO STUDENT LIBRARY *\n"); 50 | printf("\t\t\t * ---------------------------- *\n"); 51 | printf("\t\t\t * *\n"); 52 | printf("\t\t\t * *\n"); 53 | printf("\t\t\t ****************************************\n"); 54 | printf("\n\n"); 55 | printf("\t\t\t ****************************************\n"); 56 | printf("\t\t\t * *\n"); 57 | printf("\t\t\t * ------------------------ *\n"); 58 | printf("\t\t\t * STUDENT LIBRARY *\n"); 59 | printf("\t\t\t * ------------------------ *\n"); 60 | printf("\t\t\t * *\n"); 61 | printf("\t\t\t * *\n"); 62 | printf("\t\t\t * Mumbai,Maharashtra,India *\n"); 63 | printf("\t\t\t * Email: studentlib@gmail.com *\n"); 64 | printf("\t\t\t * Contact:8800991010,8800992020 *\n"); 65 | printf("\t\t\t * *\n"); 66 | printf("\t\t\t ****************************************\n"); 67 | printf("\n\n\t\t\t Press any key to continue: "); 68 | getch(); 69 | } 70 | 71 | void main_menu(){ 72 | int choice; 73 | do{ 74 | printf("\n\n"); 75 | printf("\n\t\t\t*************************************************\n"); 76 | printf("\n\t\t\t\t MAIN MENU: "); 77 | printf("\n\t\t\t\t 1.ISSUE OF BOOKS "); 78 | printf("\n\t\t\t\t 2.RETURN OF BOOKS "); 79 | printf("\n\t\t\t\t 3.DISPLAY STUDENT DETAILS "); 80 | printf("\n\t\t\t\t 4.EXIT\n "); 81 | printf("\n\t\t\t*************************************************\n"); 82 | printf("\n\t\t\t\t Enter your choice: "); 83 | scanf("%d",&choice); 84 | switch(choice){ 85 | case 1:{ 86 | start=book_issue(start); 87 | break; 88 | } 89 | case 2:{ 90 | start=book_return(start); 91 | break; 92 | } 93 | case 3:{ 94 | display(start); 95 | break; 96 | } 97 | case 4:{ 98 | exit(1); 99 | } 100 | default:{ 101 | printf("\n\t\t\t\t ...Invalid Option!...\n"); 102 | printf("\n\t\t\t\t Press any key to try again: "); 103 | getch(); 104 | } 105 | } 106 | }while(choice!=4); 107 | } 108 | 109 | struct book *initialize_lib(struct book *start){ 110 | struct book *ptr,*new_book1,*new_book2,*new_book3,*new_book4,*new_book5; 111 | 112 | new_book1=(struct book *)malloc(sizeof(struct book)); 113 | new_book1->next=NULL; 114 | start_lib=new_book1; 115 | strcpy(new_book1->name,"The Kite Runner"); 116 | strcpy(new_book1->author,"Khaled Hosseini"); 117 | new_book1->id=101; 118 | ptr=new_book1; 119 | 120 | new_book2=(struct book*)malloc(sizeof(struct book)); 121 | new_book2->next=NULL; 122 | strcpy(new_book2->name,"To Kill A Mockingbird"); 123 | strcpy(new_book2->author,"Harper Lee"); 124 | new_book2->id=102; 125 | ptr->next=new_book2; 126 | ptr=new_book2; 127 | 128 | new_book3=(struct book*)malloc(sizeof(struct book)); 129 | new_book3->next=NULL; 130 | strcpy(new_book3->name,"The Alchemist"); 131 | strcpy(new_book3->author,"Paulo Coelho"); 132 | new_book3->id=103; 133 | ptr->next=new_book3; 134 | ptr=new_book3; 135 | 136 | new_book4=(struct book*)malloc(sizeof(struct book)); 137 | new_book4->next=NULL; 138 | strcpy(new_book4->name,"Pride And Prejudice"); 139 | strcpy(new_book4->author,"Jane Austen"); 140 | new_book4->id=104; 141 | ptr->next=new_book4; 142 | ptr=new_book4; 143 | 144 | new_book5=(struct book*)malloc(sizeof(struct book)); 145 | new_book5->next=NULL; 146 | strcpy(new_book5->name,"A Tale Of Two Cities"); 147 | strcpy(new_book5->author,"Charles Dickens"); 148 | new_book5->id=105; 149 | ptr->next=new_book5; 150 | 151 | return start_lib; 152 | } 153 | 154 | struct student *book_issue(struct student *start){ 155 | struct book *ptr; 156 | struct student *ptr2,*new_student; 157 | int i=1,id,flag=0; 158 | if(start_lib==NULL){ 159 | printf("\n\t\t\t\t No books left in the library to issue!\n\t\t\t\t Sorry for the inconvenience!\n"); 160 | }else{ 161 | system("cls"); 162 | ptr=start_lib; 163 | printf("\n\t*************** Books Available: ****************\n"); 164 | while(ptr!=NULL){ 165 | printf("\n\t_________________________________________________\n"); 166 | printf("\n\t Book %d",i); 167 | printf("\n\t Book Title: %s",ptr->name); 168 | printf("\n\t Name of Author: %s",ptr->author); 169 | printf("\n\t Book ID: %d",ptr->id); 170 | printf("\n\t_________________________________________________\n"); 171 | ptr=ptr->next; 172 | i++; 173 | } 174 | printf("\n\n\t Enter the Book ID: "); 175 | scanf("%d",&id); 176 | ptr=start_lib; 177 | while(ptr!=NULL){ 178 | if(ptr->id==id){ 179 | flag=1; 180 | break; 181 | } 182 | ptr=ptr->next; 183 | } 184 | if(flag==1){ 185 | ptr=start_lib; 186 | while(ptr->id!=id){ 187 | ptr=ptr->next; 188 | } 189 | new_student=(struct student *)malloc(sizeof(struct student)); 190 | printf("\n\t Enter Student Details:\n "); 191 | printf("\n\t Enter your Name: "); 192 | scanf("%s",new_student->name); 193 | printf("\n\t Enter your Email: "); 194 | scanf("%s",new_student->email); 195 | strcpy(new_student->book,ptr->name); 196 | strcpy(new_student->a,ptr->author); 197 | new_student->id=ptr->id; 198 | new_student->next=NULL; 199 | printf("\n\t Issue of Book ID %d done successfully!\n",new_student->id); 200 | printf("\n\n\t*************************************************\n"); 201 | if(start==NULL){ 202 | start=new_student; 203 | }else{ 204 | ptr2=start; 205 | while(ptr2->next!=NULL){ 206 | ptr2=ptr2->next; 207 | } 208 | ptr2->next=new_student; 209 | } 210 | start_lib=delete_book(new_student->id); 211 | printf("\n\n\t Press any key to go to the main menu: "); 212 | getch(); 213 | system("cls"); 214 | }else{ 215 | printf("\n\t\t ...Invalid Option!...\n"); 216 | printf("\n\t\t Press any key to try again: "); 217 | getch(); 218 | system("cls"); 219 | } 220 | } 221 | return start; 222 | } 223 | 224 | struct student *book_return(struct student *start){ 225 | struct student *ptr,*preptr; 226 | char bookname[30],authorname[30]; 227 | int flag=0,id,identity,c=0,d=1; 228 | printf("\n\n\t*************** Books Submission: ****************\n"); 229 | printf("\n\n\t Enter your Book ID: "); 230 | scanf("%d",&identity); 231 | ptr=start; 232 | while(ptr!=NULL){ 233 | if(ptr->id==identity){ 234 | flag=1; 235 | break; 236 | } 237 | ptr=ptr->next; 238 | } 239 | if(flag==1){ 240 | ptr=start; 241 | while(ptr!=NULL){ 242 | c++; 243 | ptr=ptr->next; 244 | } 245 | ptr=start; 246 | while(ptr->id!=identity){ 247 | d++; 248 | ptr=ptr->next; 249 | } 250 | ptr=start; 251 | if( d==1 ){ 252 | printf("\n\t_________________________________________________\n"); 253 | printf("\n\t Student Name: %s",start->name); 254 | printf("\n\t Student Email: %s",start->email); 255 | printf("\n\t Name of Book Issued: %s",start->book); 256 | printf("\n\t_________________________________________________\n"); 257 | printf("\n\n\t Return of Book ID %d done successfully!\n",identity); 258 | printf("\n\n\t*************************************************\n"); 259 | strcpy(bookname,start->book); 260 | strcpy(authorname,start->a); 261 | id=start->id; 262 | start=start->next; 263 | free(ptr); 264 | add_book(bookname,authorname,id); 265 | }else{ 266 | ptr=start; 267 | while(ptr->id!=identity){ 268 | preptr=ptr; 269 | ptr=ptr->next; 270 | } 271 | printf("\n\t_________________________________________________\n"); 272 | printf("\n\t Student Name: %s",ptr->name); 273 | printf("\n\t Student Email: %s",ptr->email); 274 | printf("\n\t Name of Book Issued: %s",ptr->book); 275 | printf("\n\t Book ID: %d",ptr->id); 276 | printf("\n\t_________________________________________________\n"); 277 | strcpy(bookname,ptr->book); 278 | strcpy(authorname,ptr->a); 279 | id=ptr->id; 280 | preptr->next=ptr->next; 281 | free(ptr); 282 | add_book(bookname,authorname,id); 283 | } 284 | printf("\n\t Thank you! \n\t Do visit again! "); 285 | printf("\n\n\t Press any key to go to the main menu: "); 286 | getch(); 287 | system("cls"); 288 | }else{ 289 | printf("\n\tSorry the book doesn't exist! Please recheck the entered ID"); 290 | printf("\n\t\t\t\t Press any key to try again: "); 291 | getch(); 292 | system("cls"); 293 | } 294 | return start; 295 | } 296 | 297 | void display(struct student *start){ 298 | struct student *ptr; 299 | ptr=start; 300 | while(ptr!=NULL){ 301 | printf("\n\t************* Details of Students: **************\n"); 302 | printf("\n\t_________________________________________________\n"); 303 | printf("\n\t\t Student Name: %s",ptr->name); 304 | printf("\n\t\t Student Email: %s",ptr->email); 305 | printf("\n\t\t Name of Book Issued: %s",ptr->book); 306 | printf("\n\t\t Book ID: %d",ptr->id); 307 | printf("\n\t_________________________________________________\n"); 308 | printf("\n\n\t*************************************************\n"); 309 | ptr=ptr->next; 310 | } 311 | printf("\n\n\t Press any key to go to the main menu: "); 312 | getch(); 313 | system("cls"); 314 | } 315 | 316 | struct book *delete_book(int id){ 317 | struct book *ptr,*preptr; 318 | int c=0; 319 | ptr=start_lib; 320 | while(ptr!=NULL){ 321 | c++; 322 | ptr=ptr->next; 323 | } 324 | if(c==1){ 325 | ptr=start_lib; 326 | start_lib=NULL; 327 | free(ptr); 328 | }else if(start_lib->id==id){ 329 | ptr=start_lib; 330 | start_lib=start_lib->next; 331 | free(ptr); 332 | }else{ 333 | ptr=start_lib; 334 | while(ptr->id!=id){ 335 | preptr=ptr; 336 | ptr=ptr->next; 337 | } 338 | preptr->next=ptr->next; 339 | free(ptr); 340 | } 341 | return start_lib; 342 | } 343 | 344 | struct book *add_book(char bookname[30],char authorname[30],int id){ 345 | struct book *ptr,*new_book; 346 | new_book=(struct book *)malloc(sizeof(struct book)); 347 | strcpy(new_book->name,bookname); 348 | strcpy(new_book->author,authorname); 349 | new_book->id=id; 350 | new_book->next=NULL; 351 | if(start_lib==NULL){ 352 | start_lib=new_book; 353 | }else{ 354 | ptr=start_lib; 355 | while(ptr->next!=NULL){ 356 | ptr=ptr->next; 357 | } 358 | ptr->next=new_book; 359 | } 360 | return start_lib; 361 | } 362 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library-Management-System-using-Data-Structures 2 | 3 | Library management system is a simple console application using linked list in C programming language. User can perform basic library management operations like issuing books, returning the issued books and displaying records of the issued books with the user details. 4 | 5 | Each book in the library has a unique identification number. The user issues the book by entering the book ID and the user details. Each user can issue only one book at a time. When the user returns the issued book, the book is available in the library for issuing again. The record of the issued book with user details can also be viewed. 6 | 7 | 8 | --------------------------------------------------------------------------------