當前位置:編程學習大全網 - 編程軟體 - c語言 結構體 編程

c語言 結構體 編程

立壹個記錄學生學號和期中·期末成績的系統(可以運行,但是每次會彈出問題框,使因為p1->next沒有指向空指針)

#include<stdio.h>

#include<windows.h>

struct student

{ int num;

float mid;

float end;

struct student *next;};

int n;

struct student *lucifer()

{struct student *head,*p1,*p2;

n=0;

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

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

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

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

while(p1->num!=0)

{n=n+1;

if(n==1) head=p1;

else p2->next=p1;

p2=p1;

p1=(struct student*)malloc(sizeof(struct student));

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

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

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

}

return(head);

}p1->next=NULL;

void main()

{printf("請輸入學生學號和期中期末成績\n");

struct student *p;

p=lucifer();

do{printf("學號是%d\t期中成績%f\t期末成績%f\n",p->num,p->mid,p->end);

p=p->next;}

while(p!=NULL);

}這個應該可以額 有什麽可以交流

  • 上一篇:各位師傅,我想自己動手改裝壹臺氣動儀表車床,工作步驟是這樣的A氣缸到B氣缸A氣缸再回來怎麽能控制這兩個
  • 下一篇:如何通過編程記錄壹個字符的距離
  • copyright 2024編程學習大全網