67 lines
2.3 KiB
C
67 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
typedef struct book {
|
|
char *name;
|
|
double price;
|
|
int page_quantity;
|
|
char *language;
|
|
int weight_grams;
|
|
int year_published;
|
|
struct book *next;
|
|
} HPBook;
|
|
|
|
void new_book(HPBook *book, char *name, double price, int page_quantity, char *language, int weight_grams, int year_published, HPBook *next) {
|
|
book->name = name;
|
|
book->price = price;
|
|
book->page_quantity = page_quantity;
|
|
book->language = language;
|
|
book->weight_grams = weight_grams;
|
|
book->year_published = year_published;
|
|
book->next = next;
|
|
}
|
|
|
|
void print_book(HPBook *book) {
|
|
printf("Name: %s\n", book->name);
|
|
printf(" Price: %.2lf\n", book->price);
|
|
printf(" Pages: %d\n", book->page_quantity);
|
|
printf(" Language: %s\n", book->language);
|
|
printf(" Year of publication: %d\n", book->year_published);
|
|
for (int i = 0; i < 50; i++) {
|
|
printf("─");
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void print_linked_list(HPBook *book) {
|
|
while (book != NULL) {
|
|
print_book(book);
|
|
book = book->next;
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
HPBook *head = NULL, *philosopher = NULL, *chamber = NULL, *prisoner = NULL, *goblet = NULL, *order = NULL, *prince = NULL, *hallows = NULL;
|
|
|
|
philosopher = (HPBook *) malloc(sizeof(HPBook));
|
|
chamber = (HPBook *) malloc(sizeof(HPBook));
|
|
prisoner = (HPBook *) malloc(sizeof(HPBook));
|
|
goblet = (HPBook *) malloc(sizeof(HPBook));
|
|
order = (HPBook *) malloc(sizeof(HPBook));
|
|
prince = (HPBook *) malloc(sizeof(HPBook));
|
|
hallows = (HPBook *) malloc(sizeof(HPBook));
|
|
|
|
new_book(philosopher, "Harry Potter and the Philosopher's Stone", 990, 248, "Ua", 100, 2016, chamber);
|
|
new_book(chamber, "Harry Potter and the Chamber of Secrets", 990, 272, "Ua", 100, 2016, prisoner);
|
|
new_book(prisoner, "Harry Potter and the Prisoner of Azkaban", 1100, 336, "Ua", 100, 2017, goblet);
|
|
new_book(goblet, "Harry Potter and the Goblet of Fire", 1200, 464, "Ua", 100, 2019, order);
|
|
new_book(order, "Harry Potter and the Order of the Phoenix", 1400, 576, "Ua", 100, 2022, prince);
|
|
new_book(prince, "Harry Potter and the Half-Blood Prince", 420, 576, "Ua", 100, 2005, hallows);
|
|
new_book(hallows, "Harry Potter and the Deathly Hallows", 420, 640, "Ua", 100, 2007, NULL);
|
|
|
|
head = philosopher;
|
|
print_linked_list(head);
|
|
|
|
return 0;
|
|
}
|