写的链表怎么输入和输出都做不到?求指点求开导
程序代码:# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>
# include <string.h>
# define NULL 0
int len; //定义当前已存放的学生个数
struct student
{
char num[9];
char name[9];
float language;
float math;
float english;
float average;
struct student * next;
};
struct student * input(void);
void output(struct student * );
//struct student * sort(struct student * );
void sinput(struct student * );
int main (void)
{
int n;
struct student * head = NULL;
do
{
system("cls");
printf("\t主菜单\n");
printf("================================\n");
printf("1.输入学生成绩\n");
printf("2.插入学生成绩\n");
printf("3.显示成绩优秀的学生成绩\n");
printf("4.按学生学号查询学生成绩\n");
printf("5.按学生姓名查询学生成绩\n");
printf("6.显示所有学生成绩\n");
printf("0.退出系统\n");
printf("================================\n");
printf("请选择(0~6):");
scanf("%d",&n);
switch(n)
{
case 0:break;
case 1:system("cls");
head = input();
break;
case 6:system("cls");
output(head);
break;
}
}while(n != 0);
printf("谢谢使用!\n");
return 0;
}
//单次输入函数
void sinput(struct student * p1)
{
printf("请输入学号:");
scanf("%s",p1->num);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请输入语文成绩:");
scanf("%f",&p1->language);
printf("请输入数学成绩:");
scanf("%f",&p1->math);
printf("请输入英语成绩:");
scanf("%f",&p1->english);
p1->average = (p1->language+p1->math+p1->english)/3;
system("cls");
printf("您刚输入的学生信息为:\n");
printf(" 学号 姓名 语文 数学 英语 平均分\n");
printf("%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",len,p1->num,p1->name,
p1->language,p1->math,p1->english,p1->average);
return ;
}
//学生成绩录入函数
struct student * input(void)
{
struct student * phead,* p1,*p2;
char ch = 'y';
len = 1;
p1 = p2 = (struct student *)malloc(sizeof(struct student));
printf("请输入第%d个学生的信息:\n",len);
sinput(p1);
printf("继续输入按任意键或按n退出输入\n");
scanf(" %c",&ch);
phead = NULL;
while(ch != 'N'&&ch != 'n')
{
len++;
if(len == 2)phead = p1;
else p2->next = p1;
p2 = p1;
p1 = (struct student *)malloc(sizeof(struct student));
system("cls");
printf("请输入第%d个学生的信息:\n",len);
sinput(p1);
printf("继续输入按任意键或按n退出输入\n");
scanf(" %c",&ch);
}
p2->next=NULL;
// phead = sort(phead);
system("cls");
printf("\n\n按任意键返回主菜单……");
getchar();
getchar();
return phead;
}
void output(struct student * phead)
{
struct student * p1;
int i = 1;
p1 = phead;
printf(" 学号 姓名 语文 数学 英语 平均分\n");
while(phead != NULL)
{
do
{
printf("%d\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n",i,p1->num,p1->name,
p1->language,p1->math,p1->english,p1->average);
p1 = p1->next;
i++;
}while(p1 != NULL);
}
printf("\n\n按任意键返回主菜单……");
getchar();
getchar();
return ;
}









