2016-06-11 4 views

답변

1

은 보호가 필요하다. 가능한 해결책 :

void sort_alpha(t_file **begin_list) 
{ 
t_file *list; 
char *tmp; 

list = *begin_list; 
if (list) 
{ 
    while (list && list->next) 
    { 

     if (strcmp(list->file_name, list->next->file_name) < 0) 
     { 
      tmp = list->file_name; 
      list->file_name = list->next->file_name; 
      list->next->file_name = tmp; 
     } 
     list = list->next; 
    } 
} 
} 
+0

알파벳 순서로 정렬하지 않아서 내 정렬 알고리즘이 작동하지 않는 것처럼 보입니다. –

0

해서 listlist->next도 null가 아닌 것을 의미하는 것은 아니다 null가 아닌; 그것을 사용하기 전에 그것이 아닌지 확인하십시오. 라인

 if (strcmp(list->file_name, list->next->file_name) < 0) 

     // list->next could be NULL so 
     // list->next->file_name could give seg fault 

에서