EncoreLaw 2016-05-21 07:04 采纳率: 46.2%
浏览 1226
已结题

这个程序insert()函数为什么不会执行啊

#include
#include
#define LEN sizeof(struct student)
struct student
{
int num;
int score;
struct student *next;
};
int n=0;
struct student *creat()
{

struct student *head=NULL,*p1,*p2;
p1=p2=(struct student*)malloc(LEN);
printf("Please enter the numbers and scores of the students(enter 0 maens finishing input):\n");
scanf("%d %d",&p1->num,&p1->score);
while(p1->num!=0)
{ 
    n++;
    if(n==1)head=p1;
    else p2->next=p1;
    p2=p1;
    p1=(struct student*)malloc(LEN);
    scanf("%d %d",&p1->num,&p1->score);

}
p2->next=NULL;
free(p1);
return head;

}
struct student insert(int num,int score,struct student *p)
{

struct student *a,*t;
a=t=(struct student
)malloc(LEN);
a->num=num,a->score=score;
while(p->next!=NULL)
{
if(p->num>a->num)
{t->next=a;a->next=p;break;}
t=p;
p=p->next;
}
if(p->next=NULL){p->next=a;a->next=NULL;}
return t;
}

int main()
{
struct student *pt;
int num,score;
pt=creat();
printf("please enter a number and a score to insert into the database:\n");
scanf("%d %d",&num,&score);
insert(num,score,pt);
while(pt!=NULL)
{
printf("num:%d score:%d\n",pt->num,pt->score);
pt=pt->next;
}

return 0;

}

  • 写回答

5条回答 默认 最新

  • 布兰.德瓦登 2016-05-21 07:33
    关注

    肯定能执行啊,编译完不执行?

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)