有关单向链表的建立问题,恳求高手解惑。
typedef struct node{
char name[10];
int age;
char sex[5];
char telephonenumber[20];
char adress[20];
struct node *link;
}STU;
STU *creat_list(int n)
{
STU *h,*p,*s;
int i;
if(h=(STU *)malloc(sizeof(STU))==NULL)
{
printf("Don't have enough space!\n");
exit(0);
}
h->name[0]='\0';
h->age=0;
h->sex[0]='\0';
h->telephonenumber[0]='\0';
h->adress[0]='\0';
h->link=NULL;
p=h;
for(i=0;i<n;i++)
{
if(s=(STU *)malloc(sizeof(STU))==NULL)
{
printf("Don't have enough space!\n");
exit(0);
}
p->link=s;
printf("Please input NO.%d student's name:",i+1);
scanf("%s",s->name);
printf("Please input NO.%d student's age:",i+1);
scanf("%d",&s->age);
printf("Please input NO.%d student's sex(boy/girl):",i+1);
scanf("%s",s->sex);
printf("Please input NO.%d student's telephone number:",i+1);
scanf("%s",s->telephonenumber);
printf("Please input NO.%d student's adress:",i+1);
scanf("%s",s->adress);
printf("\n");
s->link=NULL;
p=s;
}
return h;
}
为什么STU *creat_list(int n)返回值是NULL,而不是第一个结点的地址呢?