请大神来帮我看下指针的问题。调释没有问题,运行有错误。感觉逻辑应该没有问题。可是。(绝对不是作业题目。)。
程序代码:
#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<string.h> #define TRUE 1 #define FALSE 0 struct Length { char name[20]; char phone[20]; struct Length *next; struct Length *previous; }; int sll_daxiao(struct Length *xiao,struct Length *da); int sll_charu(struct Length *xian,struct Length *hou); int main(void) { struct Length *current = NULL; struct Length *first = NULL; struct Length *last = NULL; char test = '\0'; for(;;) { printf("请问是否能填写电话簿请选择(Y or N):"); scanf(" %c",&test); if(tolower(test) == 'n') break; current = (struct Length*)malloc(sizeof(struct Length)); if(first == NULL) { first = current; current ->previous =NULL; } else { last ->next = current; current ->previous = last; } printf("请输出想填写电话人的姓名:"); scanf("%s",current ->name); printf("请输入%s的电话号码:",current ->name); scanf("%s",current ->phone); current ->next = NULL; last = current; } current = first; while(current != NULL) { if(!(sll_charu(current,current->next))) { current = current ->next; continue; } else current = current ->next; } current = first; while(current != NULL) { printf("\n%s的电话号码是%s\n",current->name,current->phone); last = current; current = current ->next; } current = last; while(current != NULL) { printf("\n%s的电话号码是%s\n",current->name,current->phone); last = current; current = current ->previous; free(last); } return 0; } int sll_daxiao(struct Length *da,struct Length *xiao) { if(strcmp(da->name,xiao->name)<0) return TRUE; else return FALSE; } int sll_charu(struct Length *xian,struct Length *hou) { struct Length *first; struct Length *last; if(hou ==NULL || xian == NULL) return 0; last = hou -> next; first = xian ->previous; if(sll_daxiao(xian,hou)) { first ->next = hou; hou -> next =xian; xian ->next = last; last ->previous = xian; xian -> previous = hou; hou ->previous = first; return 1; } return 0; } //题目是要求存储手机号码和个人姓名。 按姓名的大小排序。利用链表。 //感觉逻辑应该没有错。。可是。。- - 请大神来帮我指出错误。最好给一些标准代码。。谢谢。。