我这个现在可以运行,而且要注意输入的数据不能超过数组容量
不知道你的问题,具体出在了哪里。。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
struct student
{
int num;
float score;
struct student *next;
};
void main()
{
struct student *p1, *p2, *head;
struct student student[10];
int n, i;
i = 0;
printf("Please enter the student's number and score: \n");
printf("Number:");
scanf("%d", &student[0].num);
printf("Score:");
scanf("%f", &student[0].score);
p1 = &student[0];
p2 = &student[0];
head = NULL;
n = 0;
while ((*p1).num != 0)
{
n = n + 1;
if (n == 1)
{
head = p1;
}
else
{
(*p2).next = p1;
}
p2 = p1;
i++;
p1 = &student[i];
printf("\n\nPlease enter the student's number and score: \n");
printf("Number:");
scanf("%d", &student[i].num);
int ch;
while ((ch = getchar()) != EOF && ch != '\n')
{
;
}
printf("Score:");
scanf("%f", &student[i].score);
}
(*p1).next = NULL;
}
|