|
发表于 2019-11-11 12:03:44
|
显示全部楼层
#include<stdio.h>
struct Book
{
char title[128];
char author[40];
float price;
unsigned int date;
char publisher[40];
}book;
int main(void)
{
printf("请输入书名:");
scanf_s("%s", book.title, 128); //128
printf("请输入作者:");
scanf_s("%s", book.author, 40); //40
printf("请输入售价:");
scanf_s("%f", &book.price);
printf("请输入出版日期:");
scanf_s("%d", &book.date);
printf("请输入出版社:");
scanf_s("%s", book.publisher, 40); //40
printf("书名:%s\n", book.title);
printf("作者:%s\n", book.author);
printf("售价:%.2f\n", book.price);
printf("出版日期:%d\n", book.date);
printf("出版社:%s\n", book.publisher);
return 0;
}
vs下scanf_s输入字符串时加上缓冲区长度参数就好了。 |
|