#include <stdio.h>
#define total 2
struct author {
char FirstName[20];
char LastName[20];
char sex[10];
};
struct book {
char title[20];
float value;
struct author author;
};
int main() {
int i; for( i=0;i<total;i++)
{
printf("输入这本书的标题:");
scanf("%c",&book.title);
printf("输入这本书的价钱:");
scanf("%f",&book.value);
printf("输入这本书的作者姓和名:"); scanf("%c%c",&author.FirstName,&author.LastName);
printf("输入作者的性别:");
scanf("%c",&author.sex);
}
printf("标题:%c\n",&book.title);
printf("价格:%f\n",&book.value);
printf("作者的姓和名:%c%c\n",&author.FirstName,&author.LastName); printf("作者的性别:%c\n",&author.sex);
return 0;
}
谢谢,可是还是不能输出,不晓得为什么啊
追答你的book是结构体名而不是变量名,你需要再定义一个,比如struct book b;
然后输入、输出用b.xxx