#include <stdio.h>
#include <malloc.h>
#define N 10
typedef struct node
{
char name[20];
struct node *link;
}stud;
stud *creat(int n)
{
stud *p,*h,*s;
int i;
if((h = (stud *)malloc(sizeof(stud))) == NULL)
{
printf("内存分配错误");
}
h->name[0] = '\0';
h->link = NULL;
p = h;
for(i=0;i<n;i++)
{
if((s=(stud *)malloc(sizeof(stud)))==NULL)
{
printf("error");
}
p->link = s;
printf("请输入第%d个人的姓名",i+1);
scanf("%s",s->name);
s->link = NULL;
p = s;
}
return (h);
}
main()
{
int number;
stud *head;
number = N;
head = creat(number);
}
C语言链表
最新推荐文章于 2024-02-27 17:53:45 发布