Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <locale.h>
- #include <string.h>
- #define LIMIT 5
- #define TITLE_BUFFER 80
- #define AUTHOR_BUFFER 64
- enum points { TITLE, AUTHOR, YEAR };
- typedef struct Book {
- char title[TITLE_BUFFER];
- char author[AUTHOR_BUFFER];
- int year;
- } BOOK;
- typedef BOOK* PBOOK;
- void user(enum points);
- BOOK input();
- void fill(PBOOK);
- void print(BOOK);
- void show(PBOOK);
- int compare(const void*, const void*);
- int main() {
- BOOK book[LIMIT];
- fill(book);
- system("cls");
- show(book);
- qsort(book, LIMIT, sizeof(BOOK), compare);
- show(book);
- fflush(stdin);
- getchar();
- return 0;
- }
- int compare(const void* a, const void* b) {
- PBOOK pa = a;
- PBOOK pb = b;
- return strcmp(pa->author, pb->author);
- }
- void fill(PBOOK pbook) {
- int i;
- for (i = 0; i < LIMIT; ++i) pbook[i] = input();
- }
- BOOK input() {
- BOOK book;
- user(TITLE);
- gets_s(book.title, TITLE_BUFFER);
- user(YEAR);
- scanf_s("%i", &book.year);
- fflush(stdin);
- user(AUTHOR);
- gets_s(book.author, AUTHOR_BUFFER);
- return book;
- }
- void show(PBOOK pbook) {
- int i;
- for (i = 0; i < LIMIT; ++i) print(pbook[i]);
- printf("\n");
- }
- void print(BOOK book) {
- printf(" %s, %s, %d", book.author, book.title, book.year);
- printf("\n");
- }
- void user(enum points point) {
- setlocale(LC_CTYPE, ".1251");
- switch (point) {
- case TITLE: printf(" Введите название книги: "); break;
- case AUTHOR: printf(" Введите автора: "); break;
- case YEAR: printf(" Введите год издания: "); break;
- }
- setlocale(LC_CTYPE, ".866");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement