求大神看一看我这个动态链表的函数怎么不能用
代码如下:#include <stdio.h>
#include <malloc.h>
struct student
{
char name[10];
struct student *next;
};
struct student *Input(int n)
{
int i;n=0;
struct student *s,*r,*head;
r=s=(struct student*)malloc(sizeof(struct student));
for(i=0;i<n;i++)
{
printf("请输入第%d个学生的姓名:",n+1);
scanf("%s",&s->name);
if(i==0)
r=head;
if(i>0)
r->next=s;
r=s;
s=(struct student*)malloc(sizeof(struct student));
}
r->next=NULL;
return head;
}
int main()
{
int n;struct student *s;
scanf("%d",&n);
s=Input(n);
printf("%s",s->name);
return 0;
}
运行之后输入n的值之后就崩溃了。。