| bookshelf.c - Hele programmet. | Lektion 9 - slide 15 : 29 Program 1 |
#include <stdio.h>
#define MAX_BOOKS 10
struct book {
char *title, *author, *publisher;
int publishing_year;
int university_text_book;
};
typedef struct book book;
book make_book(char *title, char *author, char *publisher,
int year, int text_book){
book result;
result.title = title; result.author = author;
result.publisher = publisher; result.publishing_year = year;
result.university_text_book = text_book;
return result;
}
void prnt_book(book b){
char *yes_or_no;
yes_or_no = (b.university_text_book ? "yes" : "no");
printf("Title: %s\n"
"Author: %s\n"
"Publisher: %s\n"
"Year: %4i\n"
"University text book: %s\n\n",
b.title, b.author, b.publisher,
b.publishing_year, yes_or_no);
}
int main(void) {
book shelf[MAX_BOOKS];
int i;
shelf[0] =
make_book("C by Disssection", "Kelley & Pohl",
"Addison Wesley", 2001, 1);
shelf[1] =
make_book("Pelle Erobreren", "Martin Andersen Nexoe",
"Gyldendal", 1910, 0);
shelf[2] = shelf[1];
shelf[2].title = "Ditte Menneskebarn";
shelf[2].publishing_year = 1917;
for(i = 0; i <=2; i++)
prnt_book(shelf[i]);
return 0;
}