c programming
#include <stdio.h> #include <stdlib.h> struct book_type { // You need to fill in your struct here }; // This function loads a catalogue of books from a user specified file name. // Note you need to use malloc inside this function to allocate the memory // needed for the catalogue of books. // After catalogue is allocated and filled up with books loaded from the file, // it is returned back to the main program via the book_type * return type. // The pointer parameter numBooks is used to pass the number of books back // out to the numBooks variable in the main function. This way the other // functions will be able to use this variable to find how many books // are stored in the catalogue. struct book_type * loadCatalogue(int * numBooks); // This function saves catalogue into a user specified text file void saveCatalogue(struct book_type * bCatalogue, int numBooks); // This function displays the catalogue onto the screen. void displayCatalogue(struct book_type * bCatalogue, int numBooks); // This function finds a user specified book or set of books and displays them void findBook(struct book_type * bCatalogue, int numBooks); // Important questions for you to consider: // ** Why are the parameters for the loadCatalogue function so different // from the other functions? Please explain the difference in detail. *** // This question is not part of the assignment requirements, but it is // something that you should be able to answer since it is important // knowledge. int main() { struct book_type * bookCatalogue; int numBooks; // Write a loop which continuously asks the user to choose one of // the following options until the quit option is selected: // 1. Load catalogue from file // 2. Save catalogue to file // 3. Display catalogue // 4. Find book from catalogue // 5. Quit // // Use a switch statement to handle the different user choices. // In the case that load catalogue is chosen you should call the // loadCatalogue function as follows: // bookCatalogue = loadCatalogue(&numBooks); // // In the case that save catalogue is chosen you should call the // saveCatalogue function as follows: // saveCatalogue(bookCatalogue, numBooks); // // It is up to you to work out how and when to call the other functions. }