程序求功能模块化,尝试了好多次,不能运行出正确的结果
#include<stdio.h> #include<stdlib.h>
main()
{
int n;
typedef struct stu
{
int i;
struct stu *next;
}stu;
typedef struct head
{
stu *he;
int size;
}head;
head *p;
stu *p1;
stu *p2;
stu *p3;
p=(head*)malloc(sizeof(head));
if(p==NULL)
{
printf("shengqingshibai\n");
return (NULL);
}
(*p).he=p2=NULL;
(*p).size=0;
printf("please shurushuju:\n");
scanf("%d",&n);
while(n!=0)
{
p1=(stu*)malloc(sizeof(stu));
if(p1==NULL)
{
printf("shengqingshibai\n");
return (NULL);
}
(*p1).next=NULL;
if((*p).size==0)
{
(*p).he=p1;
p2=p1;
}
else
{
(*p2).next=p1;
p2=p1;
}
(*p1).i=n;
(*p).size++;
printf("qingshurushuju:\n");
scanf("%d",&n);
}
printf("shurushujujiesu\n");
printf("%d\n",(*p).size);
p3=(*p).he;
while(p3!=NULL)
{
printf("%d\n",(*p3).i);
p3=(*p3).next;
}
}