#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(Student)
typedef struct
{
char no[8];//8位学号
char name[20];//姓名
int price;//成绩
Student * next;
}Student;
int main()
{
Student* Build_List();
void Print(Student * head);
Student * head;
//根据指定学生个数,逐个输入学生信息
head = Build_List();
//逐个显示学生表中所有学生的相关信息
Print(head);
//根据姓名进行查找,返回此学生的学号和成绩
return 0;
}
Student* Build_List()
{
int n;
Student* head, * p1, * p2;
head = NULL;
p1 = p2 = (Student*)malloc(LEN);
scanf_s("%s", p1->no, 8);
scanf_s("%s", p1->name, 20);
scanf_s("%d", &p1->price);
while (p1->no != 0)//p1->no==0标志输入结束,链表建立完成。
{
n = n + 1;
if (n == 1)
head = p1;
else
p2->next = p1;
p2 = p1;
p1 = (Student*)malloc(LEN);
scanf_s("%s", p1->no, 8);
scanf_s("%s", p1->name, 20);
scanf_s("%d", &p1->price);
}
p2->next = NULL;
return head;
}
void Print(Student* head)
{
Student* p;
p = head;
printf("-------------------------Student List-------------------------\n");
printf("NO. NAME SCORE\n");
while (p != NULL)
{
printf("%8s%10s%5d\n", p->no, p->name, p->price);
p = p->next;
}
}
代码我放这了,这是怎么回事啊