动态链表指定位置输出不了,求解答
代码如下:#include <stdio.h>
#include <malloc.h>
struct student
{
char num[13];char name[10];char sex[10];
struct student *next;
};
struct student *Input(int n)
{
int i;
struct student *r,*s,*head;
r=s=(struct student*)malloc(sizeof(struct student));
for(i=0;i<n;i++)
{
printf("请输入第%d个学生的学号:",i+1);
scanf("%s",&s->num);
printf("请输入第%d个学生的姓名:",i+1);
scanf("%s",&s->name);
printf("请输入第%d个学生的性别:",i+1);
scanf("%s",&s->sex);
if(n==0)
head=r;
if(n>0)
{
r->next=s;
}
r=s;
s=(struct student*)malloc(sizeof(struct student));
}
r->next=NULL;
return head;
}
void Output(struct student *x,int n)
{
int count=1;
printf("请输入要调出信息的学生序号:");
scanf("%d",&n);
while(count<n)
{
x=x->next;
count++;
}
if(count==n)
{
printf("信息如下:\n");
printf("学号为:%s\n",x->num);
printf("姓名为:%s\n",x->name);
printf("性别为:%s\n",x->sex);
}
}
int main()
{
struct student *head;int n,m;
printf("请输入学生个数:");
scanf("%d",&n);
head=Input(n);
Output(head,m);
return 0;
}
输入了要输出的序号之后就崩溃了。。。