1 #include <stdio.h>
2 #include "malloc.h"
3 struct data
4 {
5 int day,month,year;
6 };
7
8 struct stu
9 {
10 char name[20];
11 long num;
12 struct data birthday; /*套的结构体类型成员*/
13 };
14
15 int main()
16 {
17 struct stu *pstudent;
18 pstudent = (struct stu *)malloc(sizeof(struct stu)); //为指针变量分配安全的地址
19 printf("Input name,number,year,month,day:\n");
20 scanf("%s",pstudent->name); /*入学生姓名、学号、出生年月日*/
21 scanf("%ld",&pstudent->num);
22 scanf("%d%d%d",&pstudent->birthday.year,
23 &pstudent->birthday.month,
24 &pstudent->birthday.day);
25 printf("\nOutputname,number,year,month,day\n");
26 /*打印输出各成员项的值*/
27 printf("%20s%10ld%10d//%d//%d\n",
28 pstudent->name,
29 pstudent->num,
30 pstudent->birthday.year,
31 pstudent->birthday.month,
32 pstudent->birthday.day
33 );
34 }