#include
#include
typedef struct student
{
int num;
char name[10];
struct student *next;
}str;
int main()
{
str *p1=NULL;
str *p2=NULL;
str *head=NULL;
p1=(str*)malloc(sizeof (struct student));
printf("input num & name:\n");
scanf("%d",&(p1->num));
scanf("%s",p1->name);
head=p1;
while(p1->num!=0)
{
p2=p1;
p1=(str*)malloc(sizeof (struct student));
printf("input num & name:\n");
scanf("%d",&(p1->num));
if(p1->num==0)
{
p2->next=p1;
break;
}
else
{
scanf("%s",p1->name);
p2->next=p1;
}
}
p2->next=NULL;
free(p1);
p1=NULL;
while(head!=NULL)
{
printf("%d %s\n",head->num,head->name);
head=head->next;
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)