I need to write a simple library program using the structure Book:
typedef struct book { char name[NAME_LENGTH]; char author[AUTHOR_NAME_LENGTH]; char publisher[PUBLISHER_NAME_LENGTH]; char genre[GENRE_LENGTH]; int year; int num_pages; int copies; } Book; When the program runs the user can take out books from the library/add books/print books etc:
#define BOOK_NUM 50 int main(){ Book books[BOOK_NUM] = { 0 }; int opt = 0, books_counter = 0, *books_counter_p; books_counter_p = &books_counter; do { print_menu(); scanf("%d", &opt); while (opt < 1 || opt > 5) { printf("Invalid option was chosen!!!\n"); print_menu(); scanf("%d", &opt); } switch (opt) { case 1: // Add book to library add_book(books, books_counter_p); break; case 2: // Take a book from library break; case 3: // Return book break; case 4: // Print all books break; case 5: // Release all memory allocated for library break; default: printf("We should not get here!\n"); } } while (opt != 5); return 0; } I need some way to store the books so I can change the library as the program runs(I don't know in advance how many books the user will add/remove during the program run).
I don't want to use dynamic memory, can I define an empty array of books this way: Book books[BOOK_NUM] = { 0 }; ? It seems to work but 0 is an int type and not a Book type, will I run into troubles?