请问下大神,这个为什么会错。麻烦调释下。。
程序代码:
#include<stdio.h> #include<ctype.h> #include<stdlib.h> struct horse { int age; int height; char name[20]; char father[20]; char mother[20]; struct horse *next; }; int main(void) { struct horse *current; struct horse *first; struct horse *previous; char test = '\0'; for(;;) { printf("请问想填写马匹的资料吗(Y or N):"); scanf(" %c",&test); if(tolower(test) =='n') break; current = (struct horse*)malloc(sizeof(struct horse*)); if(current == NULL) continue; if(first == NULL) first = current; if(previous != NULL) previous->next = current; printf("请输入马匹的名字:"); scanf("%s",current->name); printf("请输入%s的age:",current->name); scanf("%d",¤t->age); printf("请输入%s的height:",current->name); scanf("%d",¤t->height); printf("请输入%s的father名字:",current->name); scanf("%s",current->father); printf("请输入%s的mother的名字:",current->name); scanf("%s",current->mother); current->next = NULL; previous = current; } current = first; while(current != NULL) { printf("马匹的名字叫做%s,它的年龄是%d,它的身高是%d.\n",current->name,current->age,current->height); printf("他的爸爸叫做%s,他的妈妈叫做%s\n",current->father,current->mother); previous = current; current = current ->next; free(previous); } return 0; }