69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
int len;
int i,j;
struct stu {
int num;
char *name;
char sex;
};
struct stu * create() {
struct stu *ps;
printf("Input total students!\n");
scanf("%d",&len);
ps=(struct stu *)malloc(len*sizeof(struct stu));
for(i=0;i<len;i++) {
scanf("%d%s%c\n",&ps[i].num,&ps[i].name,&ps[i].sex);
}
return ps;
}
void myPrint(struct stu *ps) {
for(j=0;j<len;j++) {
printf("%d %s %c\n",ps[j].num,ps[j].name,ps[j].sex);
}
}
main() {
struct stu *p;
p=create();
myPrint(p);
getch();
return 0;
}
struct stu {
int num;
char name[32];
char sex;
};