大神们 结构指针问题!给看看
程序代码:
#include<stdio.h> #include<stdlib.h> int main() { int i; typedef struct { char xing[20]; char ming[20]; }xing_ming; xing_ming jie_zuo_zhe; typedef struct { char shu_ming[40]; xing_ming jie_zuo_zhe; float jia_ge; }book; book *zhi_book[3];//定义指向book结构的指针数组; for(i=0;i<3;i++) { zhi_book[i]=(book *)malloc(sizeof(book)); puts("请输入书籍名!"); gets(zhi_book[i]->shu_ming); puts("请输入作者的姓名!"); scanf("%s%s",zhi_book[i]->jie_zuo_zhe.xing,zhi_book[i]->jie_zuo_zhe.ming); puts("请输入书籍的价格!"); scanf("%f",zhi_book[i]->jia_ge); while(getchar()!='\n') continue; free(zhi_book[i]); } for(i=0;i<3;i++) printf("书籍的名称:%10s 书籍的作者:%6s%6s 书籍的价格:%10g\n", zhi_book[i]->shu_ming,zhi_book[i]->jie_zuo_zhe.xing,zhi_book[i]->jie_zuo_zhe.ming, zhi_book[i]->jia_ge); }程序运行输入完价格 程序就出错了!不知道怎么回事