这段简单的代码,哪儿出问题了?
#include<stdio.h>#include<stdlib.h>struct stu{ char name[20]; int no; char sex; int age; struct stu* next;};struct stu* createList(int n){ if(!n)return NULL; struct stu * head=NULL,* tail=NULL,* cur=NULL; printf("input name,number,sex,age:\n"); int i=0; for(;i<n;++i){ cur=(struct stu*)malloc(sizeof(struct stu)); cur->next=NULL; scanf("%s%d%c%d",cur->name,&(cur->no),&(cur->sex),&(cur->age)); if(tail==NULL && head==NULL){ tail=head=cur; } else{ tail->next=cur; tail=cur; } } return head;}void displayList(struct stu* head){ if(!head)return; printf("name \t number \t sex \t age \n"); struct stu* p=head; while(p){ printf("%s \t %d \t %c \t %d \n",p->name,p->no,p->sex,p->age); p=p->next; }}int main(){ int n=1; struct stu* head = createList(n); displayList(head); return 0;}