#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<malloc.h>
struct Student
{
long num;
float score;
struct Student* next;
};
struct Student* creat()
{
struct Student* head=NULL, * p1, * p2;
p1 = (struct Student*)malloc(sizeof(struct Student));
scanf("%ld,%f", &p1->num, &p1->score);
if (p1->num == 0) return NULL;
else
{
p1->next = head;//p1->next = NULL
head = p1; //当输入第一组有效数据时, 进行后插 1001,99
}//开始执行
for (; p1->num!=0;)
{
p2 = p1;
p1 = (struct Student*)malloc(sizeof(struct Student));
scanf("%ld,%f", &p1->num, &p1->score);//如果输入为0,0时 //输入第二组 1002,98时
if (p1->num == 0)
{
p2->next = NULL;
break;
}
p2->next = p1;
}
return head;
}
int main()
{
struct Student* creat();
void print(struct Student* head);
struct Student* pt;
pt = creat();
print(pt);
return 0;
}
void print(struct Student* head)
{
if (head == NULL)
{
printf("Empty!");
return;
}
printf("Scores are:\n");
for (; head != NULL; head = head->next)
{
printf("num:%ld,score:%.2f\n", head->num, head->score);
}
}
0106 C
最新推荐文章于 2024-07-24 14:04:23 发布