为什么fidelast函数出错?
#include <stdio.h>#include <stdlib.h>
typedef struct player
{
int accont;
char a[20];
int power;
struct player *next;
}PLAYER;
PLAYER *build(int num)
{
PLAYER *prept,*head;
int i;
printf("input information:\n");
PLAYER *pt=(PLAYER *)malloc(sizeof(PLAYER));
if(pt!=NULL)
{
scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
}
else
{
printf("error!\n");
exit(0);
}
for(i=1;i<num;i++)
{
PLAYER *pt=(PLAYER *)malloc(sizeof(PLAYER));
if(pt!=NULL)
{
scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
}
else
{
printf("error!\n");
exit(0);
}
}
return head;
}
PLAYER *fidelast(PLAYER *head)
{
PLAYER *pt=head;
while(pt->next!=NULL)
{
pt=pt->next;
}
return pt;
}
PLAYER *fidenode(PLAYER *head,int num)
{
int i;
PLAYER *pt=head;
for(i=1;i<num&&pt->next!=NULL;i++)
{
pt=pt->next;
}
return pt;
}
PLAYER *insertlast(PLAYER *head)
{
PLAYER *prept,*pt;
pt=(PLAYER *)malloc(sizeof(PLAYER));
if(pt!=NULL)
scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
else
exit(0);
prept=fidelast(head);
prept->next=pt;
pt->next=NULL;
return head;
}
PLAYER *insert(PLAYER *head,int num)
{
PLAYER *prept,*pt;
pt=(PLAYER *)malloc(sizeof(PLAYER));
if(pt!=NULL)
scanf("%d%s%d",&pt->accont,pt->a,&pt->power);
else
exit(0);
prept=fidenode(head,num);
pt->next=prept->next;
prept->next=pt;
return head;
}
int main()
{
PLAYER *q,*c;
int a;
printf("input how many:\n");
scanf("%d",&a);
q=build(a);
printf("input what you wan fide:\n");
scanf("%d",&a);
c=fidenode(q,a);
printf("%s",c->next);
}