Niloy007

Student's Problem

Sep 4th, 2020
1,390
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. struct database {
  4.     char bookname[50];
  5.     int studentid;
  6.     char studentname[50];
  7.     char takendate[50];
  8.     char returndate[50];
  9.     char deptname[50];
  10. };
  11. int INDEX = 0;
  12. struct database LB[200];
  13.  
  14. void insert() {
  15.     printf("Enter the name of book:\n");
  16.     fflush(stdin);
  17.     scanf("%s", LB[INDEX].bookname);
  18.     fflush(stdout);
  19.  
  20.     printf("Enter student id no:\n");
  21.     scanf("%d", &LB[INDEX].studentid);
  22.     /*
  23.  
  24.     printf("Enter the name of student:\n");
  25.     fflush(stdin);
  26.     scanf("%s", LB[INDEX].studentname);
  27.     fflush(stdout);
  28.  
  29.     printf("Enter the date when taken:\n");
  30.     fflush(stdin);
  31.     scanf("%s", LB[INDEX].takendate);
  32.     fflush(stdout);
  33.  
  34.     printf("Enter the return date:\n");
  35.     fflush(stdin);
  36.     scanf("%s", LB[INDEX].returndate);
  37.     fflush(stdout);
  38.  
  39.     printf("Enter the name of department:\n");
  40.     fflush(stdin);
  41.     scanf("%s", LB[INDEX].deptname);
  42.     fflush(stdout);
  43.     */
  44.  
  45.     printf("All information has been inserted!\n\n");
  46.     INDEX++;
  47. }
  48.  
  49. void show() {
  50.     int i;
  51.     if (INDEX == 0) {
  52.         printf("List is empty\n\n");
  53.     } else {
  54.         for (i = 0; i < INDEX; i++) {
  55.             printf("The name of Book: %s\n", LB[i].bookname);
  56.             printf("Student id no: %d\n", LB[i].studentid);
  57.             printf("Name of the student: %s\n", LB[i].studentname);
  58.             printf("Taken date: %s\n", LB[i].takendate);
  59.             printf("Return date: %s\n", LB[i].returndate);
  60.             printf("Department of the student: %s\n", LB[i].deptname);
  61.  
  62.             printf("\n");
  63.         }
  64.     }
  65. }
  66. void query() {
  67.     char desirebookname[50];
  68.     printf("Enter the name of book which need to find:\n");
  69.     scanf("%s", desirebookname);
  70.  
  71.     int i;
  72.  
  73.     if (INDEX == 0) {
  74.         printf("List is empty\n\n");
  75.         return;
  76.     }
  77.     int dsr = 0;
  78.     for (i = 0; i < INDEX; i++) {
  79.         char check[200];
  80.         strcpy(LB[i].studentname, check);
  81.  
  82.         if (strcmp(check, desirebookname) == 0) {
  83.             dsr = i;
  84.             printf("Student id no: %d\n", LB[dsr].studentid);
  85.             printf("Name of the student: %s\n", LB[dsr].studentname);
  86.             printf("Taken date: %s\n", LB[dsr].takendate);
  87.             printf("Return date: %s\n", LB[dsr].returndate);
  88.             printf("Department of the student: %s\n", LB[dsr].deptname);
  89.         }
  90.     }
  91. }
  92.  
  93. int main() {
  94.     int choice;
  95.  
  96.     while (1) {
  97.         printf("Menu\n");
  98.         printf("1. Insert data\n");
  99.         printf("2. Show database\n");
  100.         printf("3. query\n");
  101.         printf("Enter your choice:\n");
  102.         scanf("%d", &choice);
  103.  
  104.         if (choice == 1) {
  105.             insert();
  106.         } else if (choice == 2) {
  107.             show();
  108.         } else if (choice == 3) {
  109.             query();
  110.         } else if (choice == 4) {
  111.             break;
  112.         } else {
  113.             printf("Error!\n\n");
  114.         }
  115.     }
  116. }
RAW Paste Data