Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. struct book {
  7.     char name[50];
  8.     char author[50];
  9.     int idno;
  10. };
  11.  
  12. int main() {
  13.     struct book books[50];
  14.     int booklist[50];
  15.     int currentNo = 0;
  16.     int choice = 0;
  17.     int id = 0;
  18.  
  19.  
  20.     for (int x = 0; x < 50; x++) {
  21.         booklist[x] = 0;
  22.         strcpy(books[x].name, "nothing19991");
  23.     }
  24.  
  25. menu:
  26.     printf("#------ MENU ------#\n");
  27.     printf("1. Create a new book catalog. (Memory status: %d out of 50) \n", currentNo);
  28.     printf("2. Search for One. \n");
  29.     printf("3. Exit.\n\n");
  30.     printf("Enter your choice: ");
  31.  
  32.     scanf("%d", &choice);
  33.  
  34.     if (choice == 1) {
  35.         char temp[50];
  36.  
  37.         getc(stdin);
  38.         printf("\nEnter book name: ");
  39.         fgets(temp, 51, stdin);
  40.         temp[0] = toupper(temp[0]);
  41.         strcpy(books[currentNo].name, temp);
  42.  
  43.         printf("Enter book Author: ");
  44.         fgets(temp, 51, stdin);
  45.         temp[0] = toupper(temp[0]);
  46.         strcpy(books[currentNo].author, temp);
  47.  
  48.  
  49.         books[currentNo].idno = currentNo;
  50.  
  51.         printf("\n\nYour book's infos are as follows:\n\n");
  52.         printf("Book's name: %s", books[currentNo].name);
  53.         printf("Book's Author: %s\n", books[currentNo].author);
  54.         printf("** Book's ID: %d **\n\n", currentNo);
  55.         currentNo++;
  56.         choice = 0;
  57.         printf("\nPress any key to continue......");
  58.         getchar();
  59.         system("clear");
  60.         goto menu;
  61.     } else if(choice == 2) {
  62.         printf("\nEnter BOOK's ID Number: ");
  63.         scanf("%d",&id);
  64.         getc(stdin);
  65.  
  66.         if (strcmp(books[id].name, "nothing19991") !=0) {
  67.             printf("\n\nYour book's infos are as follows:\n\n");
  68.             printf("Book name: %s", books[id].name);
  69.             printf("Books Author: %s", books[id].author);
  70.             printf("\nPress any key to continue......\n\n");
  71.             getchar();
  72.             system("clear");
  73.             goto menu;
  74.         } else {
  75.             printf("\n\n** Your entered ID doesn't represent a book in the catalog! **");
  76.             printf("\nPress any key to continue......\n\n");
  77.             getchar();
  78.             system("clear");
  79.             goto menu;
  80.         }
  81.     } else if (choice == 3) {
  82.         goto exit;
  83.     } else {
  84.         printf("\n\n\n*** Wrong choice number! Enter a value between 1-3! ***\n\n");
  85.         goto menu;
  86.     }
  87.  
  88.  
  89. exit:
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement