NO

Author Topic: Qsort is case insensitive?  (Read 2813 times)

svgman

  • Guest
Qsort is case insensitive?
« on: February 26, 2008, 12:18:57 AM »
I'm sorting a linked list of pointers to structure containing file names. I call qsort, and the list comes back sorted but case-insensitive. I need it case sensitive. Pain reliever isn't helping. Any advice?

====== Code snippet ======

struct graphic_file_directory_elements_type {
      char file_name[250];
      double file_size;
      struct graphic_file_directory_elements_type *next;
};

typedef struct graphic_file_directory_elements_type graphic_file_directory_elements;

qsort(graphic_file_directory_start,number_of_files_in_directory-1, sizeof(graphic_file_directory_start),compfunc);
 return graphic_file_directory_start;
}

int compfunc(void const *x, void const *y)
{
 return strcmp(((graphic_file_directory_elements *)x)->file_name,((graphic_file_directory_elements *)y)->file_name);
 
}

severach

  • Guest
Re: Qsort is case insensitive?
« Reply #1 on: February 26, 2008, 05:14:21 AM »
I don't see how it's sorting anything at all. qsort() does not sort linked lists. It sorts arrays of constant size elements. Maybe you are pulling a folder from an NTFS system where the files are reported in case insensitive order and the qsort() buffer overflow hasn't reached the rest of your elements yet.

I hope there's a good reason why you are subtracting 1 from number_of_files_in_directory. qsort() wants a count, not the highest element number.

sizeof(graphic_file_directory_start) isn't right either. qsort() wants the size of a single element not the entire array. sizeof(graphic_file_directory_start[0]) might be correct here.