user-0 提问: 创建链表运行途中停止工作？？

回复:
user: user-1
content: 引用 3 楼 oDaBing12345678的回复:[quote=引用 2 楼 paschen 的回复:] 此外，s_gets函数返回类型为char，但最后返回的是char*，两者不一致 改了 还是有问题 #include <stdio.h> #include <stdlib.h>   //malloc #include <string.h>  //strcpy #define TSIZE 40  struct film {     char filmname[TSIZE];     int rating;     struct film *next; };  char*s_gets(char*,int);  int main() {     struct film *head,*prev,*current;     char input[TSIZE];  //创建链表     head=NULL;     printf("Enter first movie title\n");     while(s_gets(input,TSIZE)!=NULL&&input[0]!=0)      {         current=(struct film*)malloc(sizeof(struct film));            if(head==NULL)                                                                         head=current;         else             prev->next=current;                                                     current->next=NULL;               strcpy(current->filmname,input);         puts("Enter your rating<0-10>");         scanf("%d",¤t->rating);              while(getchar()!='\n')             continue;                                  puts("Enter the next movie title(empty line to stop)");         prev=current;                          }     //显示链表     if(head==NULL)         printf("No data entered\n");     else         current=head;     while(current)     {         printf("Movie:%s  Rating:%d",current->filmname,current->rating);         current=current->next;     } //释放内存 current=head; while(current!=NULL) {     current=head;               head=current->next;     free(current); } puts("Bye!"); return 0; }  char * s_gets(char*st,int n)          //删除fgets中的回车 {     char*ret_val;        char*find;        ret_val=fgets(st,n,stdin);       if(ret_val)     {         find=strchr(st,'\n');           if(find)                *find='\0';             else             while(getchar()!='\n')             continue;              }     return ret_val; }  [/quote] while (current != NULL)  改成：  while (head != NULL)  你每次循环释放掉的是current，但释放后，current仍然不为NULL，下一次循环仍会执行，而其下一个结点（也就是你赋值后的head）可能已经是NULL了

user: user-0
content: 引用 2 楼 paschen 的回复:此外，s_gets函数返回类型为char，但最后返回的是char*，两者不一致 改了 还是有问题 #include <stdio.h> #include <stdlib.h>   //malloc #include <string.h>  //strcpy #define TSIZE 40  struct film {     char filmname[TSIZE];     int rating;     struct film *next; };  char*s_gets(char*,int);  int main() {     struct film *head,*prev,*current;     char input[TSIZE];  //创建链表     head=NULL;     printf("Enter first movie title\n");     while(s_gets(input,TSIZE)!=NULL&&input[0]!=0)      {         current=(struct film*)malloc(sizeof(struct film));            if(head==NULL)                                                                         head=current;         else             prev->next=current;                                                     current->next=NULL;               strcpy(current->filmname,input);         puts("Enter your rating<0-10>");         scanf("%d",¤t->rating);              while(getchar()!='\n')             continue;                                  puts("Enter the next movie title(empty line to stop)");         prev=current;                          }     //显示链表     if(head==NULL)         printf("No data entered\n");     else         current=head;     while(current)     {         printf("Movie:%s  Rating:%d",current->filmname,current->rating);         current=current->next;     } //释放内存 current=head; while(current!=NULL) {     current=head;               head=current->next;     free(current); } puts("Bye!"); return 0; }  char * s_gets(char*st,int n)          //删除fgets中的回车 {     char*ret_val;        char*find;        ret_val=fgets(st,n,stdin);       if(ret_val)     {         find=strchr(st,'\n');           if(find)                *find='\0';             else             while(getchar()!='\n')             continue;              }     return ret_val; }

user: user-1
content: 此外，s_gets函数返回类型为char，但最后返回的是char*，两者不一致

user: user-1
content: scanf("%d", current->rating);  改成：  scanf("%d", ¤t->rating);

user: user-2
content: 数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633