#include <stdio.h>
#include <stdlib.h>
#define N sizeof(struct student)
struct student
{
int num;
struct student *next;
};
struct student *cin(void)
{
struct student *head,*p_1,*p_2;
head=p_2=p_1=(struct student *)malloc(N);
scanf("%d",&(*p_2).num);
while((*p_2).num!=0)
{
p_1=(struct student *)malloc(N);
scanf("%d",&p_1->num);
if(p_1->num==0)
break;
(*p_2).next=p_1;
p_2=p_1;
}
p_1=NULL;
(*p_2).next=0;
return head;
}
void Print(struct student *p)
{
while(p->num!=0)
{
printf("%d\n",p->num);
p=p->next;
}
}
int main(void)
{
struct student *p_3;
p_3=cin();
Print(p_3);
system("pause");
}
運行到最後會有樣的結果?
這種提示一般是指針問題,你好好檢查下程序編碼中設計指針運用句子