动态列表(循环)

#include<stdio.h>
#include<stdlib.h>

typedef struct student //typedef的功能是对struct student重新命名(STU),用起来方便
{
char name[8];
int age;
struct student*kd;
}STU;

void main()
{
STU*help,*header=NULL,pcurrent;
int i=0;
for(;i<3;i++)
{
pcurrent=(STU
)malloc(sizeof(STU));
if(i==0)
{
header=pcurrent;
}
else
{
help->kd =pcurrent;
}
help=pcurrent;
printf(“请输入你的姓名:”);
scanf("%s",pcurrent->name );
printf(“请输入你的年龄:”);
scanf("%d",&pcurrent->age );
}
while(header!=0)
{
printf("%s %d\n",header->name ,header->age );
header=header->kd ;
}
}

猜你喜欢

转载自blog.csdn.net/weixin_44262430/article/details/85248865