问题描述
- 每次程序运行到这一部都会卡住没反应,估计是tcount部分的代码有问题,望高手指点
-
#include
#include
#include
#include
#include "head.h"
void tcount(cour *head);
void mcount(cour *head);void count(cour *head)
{
int i;
while(1)
{
printf("tt请选择下一步操作:n");
printf("tt1.按课程性质统计课程门数n");
printf("tt2.找出学分大于等于3分的课程,并输出他们的信息n");
printf("tt0.返回主菜单n");
i=getch();
switch(i-48)
{
case 1:tcount(head);break;
case 2:mcount(head);break;
case 0:return;
default:printf("n按键错误,请重新选择!n");
}
}
return;
}
void tcount(cour *head)
{
cour *cur;
int sum1=0,sum2=0;
cur=head;
while(cur!=NULL)
{
while(strcmp(cur->ctype,"xx")==0)
{
sum1++;
}
while(strcmp(cur->ctype,"bx")==0)
{
sum2++;
}
cur=cur->next;
}
printf("查询结果如下n");
printf("其中有选修课:%d门n",sum1);
printf("其中有必修课:%d门n",sum2);
}
void mcount(cour *head)
{
cour *cur;
cur=head;
printf("学分大于等于3的课程信息如下所示:n");
printf("%-10s%-10s%-10s%-6s", "课程编号", "课程名称", "课程性质","学时");
printf("%-10s%-15s%-6s%sn", "授课学时","实验或上机学时","学分","开课学期");
while(cur!=NULL)
{
if(cur->mark>=3)
{
printf("%-10s%-10s%-10s%-10d", cur->cnum, cur->cname, cur->ctype,cur->time);
printf("%-10d%-12d%-12d%dn",cur->ttime,cur->etime,cur->mark,cur->term);
}
cur=cur->next;
}
}
解决方案
你这个只有在 i= 48时才能跳出tcont 。其他的时候都只能跳出swith而跳不出while循环。