Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct database {
- char bookname[50];
- int studentid;
- char studentname[50];
- char takendate[50];
- char returndate[50];
- char deptname[50];
- };
- int INDEX = 0;
- struct database LB[200];
- void insert() {
- printf("Enter the name of book:\n");
- fflush(stdin);
- scanf("%s", LB[INDEX].bookname);
- fflush(stdout);
- printf("Enter student id no:\n");
- scanf("%d", &LB[INDEX].studentid);
- /*
- printf("Enter the name of student:\n");
- fflush(stdin);
- scanf("%s", LB[INDEX].studentname);
- fflush(stdout);
- printf("Enter the date when taken:\n");
- fflush(stdin);
- scanf("%s", LB[INDEX].takendate);
- fflush(stdout);
- printf("Enter the return date:\n");
- fflush(stdin);
- scanf("%s", LB[INDEX].returndate);
- fflush(stdout);
- printf("Enter the name of department:\n");
- fflush(stdin);
- scanf("%s", LB[INDEX].deptname);
- fflush(stdout);
- */
- printf("All information has been inserted!\n\n");
- INDEX++;
- }
- void show() {
- int i;
- if (INDEX == 0) {
- printf("List is empty\n\n");
- } else {
- for (i = 0; i < INDEX; i++) {
- printf("The name of Book: %s\n", LB[i].bookname);
- printf("Student id no: %d\n", LB[i].studentid);
- printf("Name of the student: %s\n", LB[i].studentname);
- printf("Taken date: %s\n", LB[i].takendate);
- printf("Return date: %s\n", LB[i].returndate);
- printf("Department of the student: %s\n", LB[i].deptname);
- printf("\n");
- }
- }
- }
- void query() {
- char desirebookname[50];
- printf("Enter the name of book which need to find:\n");
- scanf("%s", desirebookname);
- int i;
- if (INDEX == 0) {
- printf("List is empty\n\n");
- return;
- }
- int dsr = 0;
- for (i = 0; i < INDEX; i++) {
- char check[200];
- strcpy(LB[i].studentname, check);
- if (strcmp(check, desirebookname) == 0) {
- dsr = i;
- printf("Student id no: %d\n", LB[dsr].studentid);
- printf("Name of the student: %s\n", LB[dsr].studentname);
- printf("Taken date: %s\n", LB[dsr].takendate);
- printf("Return date: %s\n", LB[dsr].returndate);
- printf("Department of the student: %s\n", LB[dsr].deptname);
- }
- }
- }
- int main() {
- int choice;
- while (1) {
- printf("Menu\n");
- printf("1. Insert data\n");
- printf("2. Show database\n");
- printf("3. query\n");
- printf("Enter your choice:\n");
- scanf("%d", &choice);
- if (choice == 1) {
- insert();
- } else if (choice == 2) {
- show();
- } else if (choice == 3) {
- query();
- } else if (choice == 4) {
- break;
- } else {
- printf("Error!\n\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement