|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<string.h>
struct student
{
int num;
float score;
struct student* next;
};
#define LEN sizeof(struct student)
struct student* creat();
void scan(struct student* head);
void print(struct student* point);
int main()
{
struct student* head = (struct student*)malloc(LEN);
struct student* point = head;
scan(head);
print(head);
}
struct student* creat()
{
struct student* list = (struct student*)malloc(LEN);
list->num = 0;
list->score = 0;
list->next = NULL;
return list;
}
void scan(struct student* head)
{
printf("please enter the num:");
scanf_s("%d", &(head->num));
printf("please enter the score:");
scanf_s("%f", &head->score);
while (head->num)
{
head->next = creat();
head = head->next;
printf("please enter the num:");
scanf_s("%d", &head->num);
printf("please enter the score:");
scanf_s("%f", &head->score);
}
}
void print(struct student* point)
{
while (point->num)
{
printf("num:%d\tscore:%.2f\n", point->num, point->score);
point = point->next;
}
}
|
|