#include "book.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Book* book_create(const char* title, const char* author, int year)
{
// initialize book
Book* book = calloc(1, sizeof(Book));
if (!book)
return NULL;
}
// initialize title and author
book->title = calloc(strlen(title), sizeof(char));
book->author = calloc(strlen(author), sizeof(char));
if (!book->title || !book->author)
strcpy(book->title, title);
strcpy(book->author, author);
book->year = year;
return book;
void book_print(const void* data)
const Book* book = (Book*)data;
printf("Book[title=%s,author=%s,year=%d]\n", book->title, book->author, book->year);
int title_eq(const void* title, const void* data)
Book* book = (Book*)data;
return !strcmp(book->title, (char*) title);