C语言链表里面的一些问题,编译器没有任何提示,反正就是不能运行,一直卡在那里
下面是我的程序
#include <stdio.h>
#include <stdlib.h>
struct stu
{
char name[20];
int f;
char d;
struct stu *pnext;
};
struct stu* newhear() //为所有学生姓名和成绩进行初始化
{
struct stu *ph, *pn, *pe;
int c, d;
printf("请输入学生总人数(不超过50人):");
scanf_s("%d", &d, 4); //输入学生总人数
pe = (struct stu*)malloc(sizeof(struct stu)); //为pe分配内存 也是第一个节点
ph = pn = pe; //使第一个学生成为头
for (c = 0; c < d; c++)
{
printf("请输入第%d个学生的姓名\n",c+1);
scanf_s("%s", pn->name, 20); //输入第一个学生的姓名和成绩
printf("成绩;\n");
scanf_s("%d",&pn->f, 4);
if (c < (d - 1))
{
pe = (struct stu*)malloc(sizeof(struct stu));
pn->pnext = pe;
pn = pe;
}
}
pn->pnext = NULL;
return ph; //返回链表的开头,便于后面调用
}
double Average(struct stu *pe)
{
struct stu *pa ;
pa = pe;
int a;
int b;
for(a = 1,b=0; pa != NULL; a++);
{
b = pa->f+b;
pa = pa->pnext;
}
b = b / a;
return b;
}
void garde(struct stu *pe,double a)
{
struct stu *pg = pe;
while (pg != NULL)
{
if ((a + 10) < pg->f)
pg->d = 'A';
if ((pg->f>=(a-10))&& (pg->f<=(a+10)));
pg->d = 'B';
if(pg->f<(a-10))
pg->d = 'C';
pg = pg->pnext;
}
}
main()
{
struct stu *pe;
double a;
pe = newhear(); //接受链表的头
a=Average(pe); //求平均分数
garde(pe,a); //调用打分系统
system("pause");
}