关于创建链表的问题
#include "stdlib.h"#include "stdio.h"
struct student{
int code;
char name[20];
float score;
struct student *next;
};
main(){
struct student *pb,*pf,*head;
int i;
pb=(struct student*)malloc(sizeof(struct student));
head=pb;
for(i=0;;i++){
printf("input code:\n");
scanf("%d",&pb->code);
printf("input name:\n");
scanf("%s",pb->name);
printf("input score:\n");
scanf("%f",&pb->score);
if(i!=3){pf=(struct student*)malloc(sizeof(struct student));pb->next=pf;pb=pf;}
else {pb->next=NULL;break;}
}
pb=head;
while(pb!=NULL){
printf("%d\t%s\t%f\t",pb->code,pb->name,pb->score);
pb=pb->next;
}
getch();
}
还是请各位高手看看把,为什么总出错。。。