qq_31989533 2016-05-18 08:36 采纳率: 0%
浏览 994

求大神帮忙看看,不知道为什么运行时候总是输不出来

#include
#include
#include
#include

typedef struct student{
char number[10];
char name[10];
int grade;
struct student *next;
}ADDR;

int menu_select();
ADDR *input(ADDR *);
void output(ADDR *);
void Avg(struct student *);
void highscore(struct student *);

#include "61.h"

void main()
{

ADDR *top;
top=(ADDR *)malloc(sizeof(ADDR));

if(top==NULL)
{
printf("memory fail!");
exit(-1);
}
top=NULL;

for( ; ; ){
    switch(menu_select())
    {

    case 1:
        input(top);
        break;
    case 2:
        output(top);
        break;
    case 3:
        Avg(top);
        break;
    case 4:
        highscore(top);
    default:
        printf("输入错误!\n");
        exit(0);
    }
}

}

#include "61.h"

ADDR *input(ADDR *top)
{
ADDR *old;
ADDR *star;

int i=0;
star=(ADDR *)malloc(sizeof(ADDR));
old=(ADDR *)malloc(sizeof(ADDR));
if(star==NULL||old==NULL) 
{
    printf("memory fail!");
    exit(-1);
}
else 
{
  {
printf("输入数据,输入0时结束. \n");
printf(" 学号 : ");
scanf("%s",star->number);
printf(" 姓名 : ");
scanf("%s",star->name);
printf(" 成绩 : ");
scanf("%d",&star->grade);
while(strcmp(star->number,"0")>0)

{
if(top==NULL)
top=star;
else

    old->next=star;
    old=star;
    star=(ADDR *)malloc(sizeof(ADDR));
    printf("继续输入数据,输入0时结束. \n");
    printf(" 学号 : ");getchar();
    gets(star->number);
    printf(" 姓名 : ");
    gets(star->name);
    printf(" 成绩 : ");
    scanf("%d",&star->grade);
    star->next=NULL;

}

free(star);

return(top);

}

}
}

#include"61.h"

int menu_select()
{
char s[2];
int cn=0;
printf("\n");
printf("1. 输入数据 \n");
printf("2. 输出数据 \n");
printf("3. 平均成绩\n");
printf("4. 最高成绩\n");
printf("5. 退出运行\n") ;
printf("\n 左边数字对应功能选择, 请选1-5: ");

for ( ; ; )
{
    gets(s);
    cn=atoi (s);
    if(cn<1|| cn>6)
        printf("\n输入错误,重选1-5");
else break;
}
return cn;

}

#include "61.h"

void output(ADDR *top)
{

if(top=NULL)
{
    printf("\n 现在没有记录 !\n");
    return;
}
printf(" 学号\t姓名\t成绩\t\n");
while(top->next!=NULL)
{
    printf("%s\t%s\t%d\n",top->number,top->name,top->grade);
    top=top->next;
}

}

  • 写回答

2条回答 默认 最新

  • 小灸舞 2016-05-18 08:41
    关注

    "61.h"文件里top==NULL写成了top=NULL
    改掉以后试试。
    单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料