请教大神,运行后只打印一行,就提示出现问题,导致程序停止正常工作。 - 爱问答

(爱问答)

请教大神,运行后只打印一行,就提示出现问题,导致程序停止正常工作。

#include <stdio.h>

#include <malloc.h>

#include <stdlib.h>

 

#define LEN sizeof(struct student)  //student结构的大小

 

struct student *creat();  //创建链表

void print(struct student *head);  //打印链表

 

struct student

{

      int num;

      float score;

      struct student *next;

};

 

int n;//全局变量,用来记录存放了多少数据

 

void main()

{

      struct student *stu;

 

      stu=creat();

      print(stu);

 

      printf(" ");

      system("pause"); 

}

 

struct student *creat()

{

      struct student *head;

      struct student *p1,*p2;

 

      p1 = p2 = (struct student *)malloc(LEN); //LEN是student结构的大小

 

      printf("Please enter the num:");

      scanf("%d",&p1->num);

      printf("Please enter the score :");

      scanf("%f",&p1->score);

 

      head=NULL;

      n=0;

      while(p1->num)

      {

            n++;

            if(1==n)

            {

                  head=p1;

            }

            else

            {

                  p2->next=p1;

            }

            p2=p1;

            p1=p1=p2=(struct student *)malloc(LEN);

 

            printf(" Please enter the num:");

            scanf("%d",&p1->num);

            printf("Please enter the score :");

            scanf("%f",&p1->score);

 

      }

      return head;

}

 

void print(struct student *head)

{

      struct student *p;

      printf(" There are %d records! ",n);

 

      p=head;

 

     if( NULL != head )

      {

            do

            {

                  printf("学号为%d的成绩是:%f ",p->num,p->score);

                  p=p->next;

            }while(NULL != p );

 

      }

 

}


1。   p1=p1=p2=(struct student *)malloc(LEN);

只要   p1=(struct student *)malloc(LEN);

就可以了

2。关键:

    return head;

前面必须有

p2->next=NULL;

否则,链表没有结尾了

最好不要用修改器,有病毒的,你安装的时候杀毒软件肯定提醒你了,是否允许或者阻止这个软件干嘛干嘛的,出现这种现象是因为安装的时候少了东西,然后你运行这个软件的时候,运行什么功能,这个软件就一直在找啊找,然后一直找不到,就发生你这个提示,在加上它软件没有对这种找不到东西的况进行处理,建议安装的时候关闭杀毒软件。

相关标签:大神

下一篇:这电脑配置能玩孤岛惊魂5吗?

上一篇:VIVOX27Pro用的是什么充电插口?

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?