Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <limits.h>
- #include <string.h>
- #include <stdlib.h>
- struct book {
- char name[50];
- char author[50];
- int idno;
- };
- int main() {
- struct book books[50];
- int booklist[50];
- int currentNo = 0;
- int choice = 0;
- int id = 0;
- for (int x = 0; x < 50; x++) {
- booklist[x] = 0;
- strcpy(books[x].name, "nothing19991");
- }
- menu:
- printf("#------ MENU ------#\n");
- printf("1. Create a new book catalog. (Memory status: %d out of 50) \n", currentNo);
- printf("2. Search for One. \n");
- printf("3. Exit.\n\n");
- printf("Enter your choice: ");
- scanf("%d", &choice);
- if (choice == 1) {
- char temp[50];
- getc(stdin);
- printf("\nEnter book name: ");
- fgets(temp, 51, stdin);
- temp[0] = toupper(temp[0]);
- strcpy(books[currentNo].name, temp);
- printf("Enter book Author: ");
- fgets(temp, 51, stdin);
- temp[0] = toupper(temp[0]);
- strcpy(books[currentNo].author, temp);
- books[currentNo].idno = currentNo;
- printf("\n\nYour book's infos are as follows:\n\n");
- printf("Book's name: %s", books[currentNo].name);
- printf("Book's Author: %s\n", books[currentNo].author);
- printf("** Book's ID: %d **\n\n", currentNo);
- currentNo++;
- choice = 0;
- printf("\nPress any key to continue......");
- getchar();
- system("clear");
- goto menu;
- } else if(choice == 2) {
- printf("\nEnter BOOK's ID Number: ");
- scanf("%d",&id);
- getc(stdin);
- if (strcmp(books[id].name, "nothing19991") !=0) {
- printf("\n\nYour book's infos are as follows:\n\n");
- printf("Book name: %s", books[id].name);
- printf("Books Author: %s", books[id].author);
- printf("\nPress any key to continue......\n\n");
- getchar();
- system("clear");
- goto menu;
- } else {
- printf("\n\n** Your entered ID doesn't represent a book in the catalog! **");
- printf("\nPress any key to continue......\n\n");
- getchar();
- system("clear");
- goto menu;
- }
- } else if (choice == 3) {
- goto exit;
- } else {
- printf("\n\n\n*** Wrong choice number! Enter a value between 1-3! ***\n\n");
- goto menu;
- }
- exit:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement