|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define W 3
typedef struct Book
{
char title[128];
char author[40];
float price;
unsigned int date;
char publisher[40];
}Book;
int main(void)
{
Book Book_one[W];
Book* Pt;
Pt = &Book_one;
//Book_one = &Book;
int i = 0;
for (i = 0;i < W;i++)
{
printf("请输入书名: ");
scanf("%s",*Pt->title);
printf("请输入作者: ");
scanf("%s",Book_one[W].author);
printf("请输入售价: ");
scanf("%f",Book_one[W].price);
printf("请输入出版日期: ");
scanf("%d",Book_one[W].date);
printf("请输入出版社: ");
scanf("%s",Book_one[W].publisher);
}
printf("\n============数据录入完毕===========\n");
for (i = 0;i < W;i++)
{
printf("书名:%s\n ", (*Pt).title);
printf("作者:%s\n ", Book_one[W].author);
printf("售价:%f\n ", Book_one[W].price);
printf("出版日期:%d\n ", Book_one[W].date);
printf("出版社:%s\n ", Book_one[W].publisher);
}
return 0;
}
我发现了两个问题:①PT是指针,Book_one[W]是数组,赋值时不需要加&
②进入for循环时Book_one[W]应该是Book_one[i]
|
|