You have already coded your solution (however, see other answers and changes at the end of this question with the choice of the used comparison function and the data transferred to qsort() ).
You can drop the wrapper function by pointing the function pointer to qsort() to the appropriate type, but I think using a wrapper is the best solution in terms of serviceability. If you really want to avoid the wrapper function (you may have encountered a measurable run into the primary problem), you can do this:
qsort(chararray, length, sizeof(wchar_t), (int(*)(const void*,const void*))wcscoll);
Or make it more readable with typedef for the type of the comparison function:
typedef int (*comp_func_t)(const void *, const void *); qsort(chararray, length, sizeof(wchar_t), (comp_func_t) wcscoll);
Unfortunately, direct C qsort() cannot be typical, so it cannot have "error handling if the arguments are not of type wchar_t". You, the programmer, are responsible for passing the correct data, sizes, and comparison function to qsort() .
Edit:
To solve some of the problems mentioned in other answers about types passed by the comparison function, a procedure is used here that can be used to sort wchar_t using the current locale matching sequence. The library may have something better, but I don't know about it at the moment:
int wchar_t_coll( const void* p1, const void* p2) { wchar_t s1[2] = {0}; wchar_t s2[2] = {0}; s1[0] = * (wchar_t*)p1; s2[0] = * (wchar_t*)p2; return wcscoll( s1, s2); }
Also note that the chararray you pass to wcslen() is not completed correctly - you will need 0 at the end of the initializer:
wchar_t chararray[] = {b, a, a1, 0};