#include <stdio.h>
#include<stdlib.h>
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;
}
C语言单链表简单的输入输出,输入学生学号,姓名,输出;
最新推荐文章于 2022-10-06 16:50:03 发布