回复 29楼 农民也疯狂
还是论坛的高手多啊
程序代码:
//建立一个链表 找出与它最接近的数据 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> struct student { char name[10]; int age; struct student *next; }; int main() { struct student *stru = (struct student*) malloc(sizeof(struct student)); struct student *first = NULL; struct student *last = NULL; char answer = 'n'; int i = 0; for(;;) { fflush(stdin); printf("名字:"); gets(stru->name); printf("年龄:"); scanf("%d",&stru->age); printf("你还想输入信息吗?(y/n):"); scanf(" %c",&answer); if(first == NULL) first = stru; if(last != NULL) last->next = stru; last = stru; stru -> next = NULL; if(tolower(answer) == 'n') break; stru = (struct student*)malloc(sizeof(struct student)); } stru = first; /*输出*/ while(stru != NULL) { printf("\n%s\t:%d",stru->name,stru->age); last = stru; stru = stru->next; free(last); } printf("\n\n"); return 0; }额,看来我又来晚了...画个圈圈诅咒你们...