从子函数中怎样把头指与尾指针都返回到主函数呢?
下面这个链表程序用子函数来建立链表,但是我想把头指针与尾指针都返回,并且赋给不同的变量,因为我后面的程序需要用到头指针与尾指针,怎样操作呢?
#include "stdafx.h"
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#define SIZE 100
struct name
{
char firstname[SIZE];
char lastname[SIZE];
struct name *next;
};
struct name * CreateList(void);
int main(void)
{
struct name *head, *end;
head = CreateList();
end = //它该怎么办呢?
return 0;
}
struct name * CreateList(void)
{
struct name *head, *move, *track, *end;
head = move = (struct name *)malloc(sizeof(struct name));
puts("Please input the information of a student:");
while(gets(move->firstname)!=NULL && move->firstname[0]!='\0')
{
gets(move->lastname);
move->next = NULL;
track = (struct name *)malloc(sizeof(struct name));
move->next = track;
move = track;
}
end = move;
return head;
}