#include <stdio.h>
struct Date
{
int year;
int month;
int day;
};
struct Book
{
char title[128];
char author[40];
float price;
struct Date date;
char publisher[40];
};
void getinput(struct Book* book);
void printbook(struct Book* book);
void getinput(struct Book* book)
{
printf("输入书名:\n");
scanf_s("%s", book->title, 128);
printf("输入作者:\n");
scanf_s("%s", book->author, 40);
printf("输入售价:\n");
scanf_s("%f", &book->price);
printf("输入出版日期:\n");
scanf_s("%d-%d-%d", &book->date.year, &book->date.month, &book->date.day);
printf("输入出版社:\n");
scanf_s("%s", book->publisher, 40);
}
void printbook(struct Book* book)
{
printf("书名:%s\n", book->title);
printf("作者:%s\n", book->author);
printf("售价:%.2f\n", book->price);
printf("出版日期:%d-%d-%d\n", book->date.year, book->date.month, book->date.day);
printf("出版社:%s\n", book->publisher);
}
int main(void)
{
struct Date date = { .year = -1,.month = -1,.day = -1 };
struct Book b1 = { .author = NULL,.title = NULL,.price = -1,.publisher = NULL };
struct Book b2 = { .author = NULL,.title = NULL,.price = -1,.publisher = NULL };
printf("录入第一本书的信息:\n");
getinput(&b1);
putchar('\n');
printf("录入第二本书的信息:\n");
getinput(&b2);
putchar('\n');
printf("\n\n录入完毕,现在开始打印....\n\n");
printf("打印第一本书的信息...\n");
printbook(&b1);
putchar('\n');
printf("打印第二本书的信息...\n");
printbook(&b2);
return 0;
}
02-23
244
12-13
245
05-14
678