// Pantea Aria // Dynamically allocate a struct and return a pointer // Complete the TODO sections below // this program is not completed. #include #include struct book { int id; int pages; }; // Function prototypes struct book *create_book(int id, int pages); void print_book(struct book *b); int main(void) { // TODO 1: // Create a book with id 101 and 250 pages struct book *b1 = create_book(101, 250); // TODO 2: // Print the book details print_book(p); // TODO 3: // Create another book with id 202 and 300 pages struct book *b2 = NULL; // your turn // TODO 4: // Print the second book // TODO 5: // Free both allocated books before program ends return 0; } // This function should: // - Allocate memory for a struct book // - Check if malloc returned NULL // - Initialise the fields // - Return the pointer struct book *create_book(int id, int pages) { // TODO 6: // Allocate memory using malloc struct book *p = malloc(sizeof(struct book)); // TODO 7: // Check if allocation failed // If NULL, print "Out of memory" and exit // you do this // TODO 8: // Set the struct fields using -> p->id = id; p->pages = pages; // TODO 9: // Return the pointer return p; } // This function should print book details // Format: Book ID: __, Pages: __ void print_book(struct book *b) { // TODO 10: // Print the struct fields using -> printf("id is %d and pages is %d", b->id, b->pages); }