小弟才疏学浅,请T版赐教
认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
#include<stdio.h>//错误啊 #include<stdlib.h> struct yi { char name[10]; int age; char address[20]; }; struct er { struct yi *boy[3]; }; void main() {int i; struct er *p; p=(struct er*)malloc(sizeof(struct er)); p->boy[0]=(struct yi *)malloc(sizeof(struct yi)*3); for(i=0;i<3;i++) scanf("%s%d%s",(p->boy[0]+i)->name,&(p->boy[0]+i)->age,(p->boy[0]+i)->address); for(i=0;i<3;i++) printf("%s\t%d\t%s\n",(p->boy[0]+i)->name,(p->boy[0]+i)->age,(p->boy[0]+i)->address); free(p->boy[0]); free(p); }另一种实现过程,今天刚跟别人学的,现学现卖
#include<stdio.h>//错误啊 #include<stdlib.h> struct yi { char name[10]; int age; char address[20]; }; struct er { struct yi boy[3]; }; void main() {int i; struct er *p; p=(struct er*)malloc(sizeof(struct er)); for(i=0;i<3;i++) scanf("%s%d%s",p->boy[i]->name,&p->boy[i]->age,p->boy[i]->address); for(i=0;i<3;i++) printf("%s\t%d\t%s\n",p->boy[i]->name,p->boy[i]->age,p->boy[i]->address); }