#include<stdio.h>
/**
* 声明结构体和定义结构体变量
* 声明:可在main内或main外,即局部和全局的关系
* 定义结构体变量,同上
*/
struct Book{
char title[128]; // 结构成员1
char author[40];
float price;
unsigned int date;
char publisher[40];
} book; // 声明结构体时定义全局的结构体变量
int main(){
// struct Book book; // 定义局部的结构体变量
printf("请输入书名:");
scanf("%s",book.title);
getchar();
printf("请输入作者:");
scanf("%s",book.author);
getchar();
printf("请输入单价:");
scanf("%f",&book.price);
getchar();
printf("请输入出版日期:");
scanf("%d",&book.date);
getchar();
printf("请输入出版社:");
scanf("%s",book.publisher);
printf("\n\n=====数据录入完毕=====\n\n");
getchar();
printf("书本%s的作者是%s,单价是%.2f,出版日期是%d,出版社是%s。",book.title,book.author,book.price,book.date,book.publisher);
return 0;
}
运行结果如下: