fork download
#include <stdio.h>
#include <string.h>

#define MAX_BOOKS 100

typedef struct {
    char author[50];
    char title[100];
    char publisher[50];
    int year;
    int num_pages;
} Book;

void set(Book* book, const char* author, const char* title, const char* publisher, int year, int num_pages) {
    strcpy(book->author, author);
    strcpy(book->title, title);
    strcpy(book->publisher, publisher);
    book->year = year;
    book->num_pages = num_pages;
}

void get(Book* book, char* author, char* title, char* publisher, int* year, int* num_pages) {
    strcpy(author, book->author);
    strcpy(title, book->title);
    strcpy(publisher, book->publisher);
    *year = book->year;
    *num_pages = book->num_pages;
}

void show(Book* book) {
    printf("Author: %s\n", book->author);
    printf("Title: %s\n", book->title);
    printf("Publisher: %s\n", book->publisher);
    printf("Year: %d\n", book->year);
    printf("Number of pages: %d\n", book->num_pages);
}

int main() {
    Book books[MAX_BOOKS];
    int num_books = 0;

    // Добавляем книги в массив
    Book book1, book2, book3;
    set(&book1, "P", "Cool", "NN", 1990, 300);
    set(&book2, "G", "Very cool", "WWW", 2010, 250);
    set(&book3, "G", "Best", "WWW", 2011, 400);
    books[num_books++] = book1;
    books[num_books++] = book2;

    // Выводим список книг заданного автора
    char author_search[50] = "P";
    printf("Books by author %s:\n", author_search);
    for (int i = 0; i < num_books; i++) {
        if (strcmp(books[i].author, author_search) == 0) {
            show(&books[i]);
        }
    }

    // Выводим список книг выпущенных заданным издателем
    char publisher_search[50] = "WWW";
    printf("\nBooks published by %s:\n", publisher_search);
    for (int i = 0; i < num_books; i++) {
        if (strcmp(books[i].publisher, publisher_search) == 0) {
            show(&books[i]);
        }
    }

    // Выводим список книг выпущенных после заданного года
    int year_search = 2000;
    printf("\nBooks published after %d:\n", year_search);
    for (int i = 0; i < num_books; i++) {
        if (books[i].year > year_search) {
            show(&books[i]);
        }
    }

    return 0;
}

Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
Books by author P:
Author: P
Title: Cool
Publisher: NN
Year: 1990
Number of pages: 300

Books published by WWW:
Author: G
Title: Very cool
Publisher: WWW
Year: 2010
Number of pages: 250

Books published after 2000:
Author: G
Title: Very cool
Publisher: WWW
Year: 2010
Number of pages: 250