I'm facing some problem in sorting algoritm.
I'm facing some problem in sorting algoritm.
Um, What might that problem be?
sorry for the incomplete posting.
I'm doing sorting for up to 500 name entries. These name might in Ascii char (upper case or lower case) or Unicode. So how to compare entries without case sensitive. Thanks.
use strcmp() or strncmp()
this could check for the priority by value of ASCII.
but you need to include <string.h>
How about if it's case sensitive. I do used "topper" to convert all entries to upper case 1st before strcmp. But it come to problems if the entries is in unicode (chinese character). So any suggestion? Thanks.
So basically you need string compare's for wide characters. Check out this function:
From MSDN: ( on return type )Code:int wcsncmp( const wchar_t *string1, const wchar_t *string2, size_t count );
< 0 string1 substring is less than string2 substring
0 string1 substring identical to string2 substring
> 0 string1 substring greater than string2 substring
If you need a case insensitive compare why not just make a copy string and convert the string to one case?
I used qsort to sort 500 name entries in ASCII or Unicode and here is my sort function. But the program reset when it try to run this function. But if i sort without case sensitive which mean i use strcmp directly i seem ok.
Code:int status, i, j; char nameStr1[PHB_MAX_LEN], nameStr2[PHB_MAX_LEN]; memset(nameStr1, 0, PHB_MAX_LEN); memset(nameStr2, 0, PHB_MAX_LEN); if(0x80 !=arg1->name[0]) { for(i=0; i<PHB_MAX_LEN;i++) nameStr1[i] = toupper(arg1->name[i]); } if(0x80 !=arg2->name[0]) { for(j=0; j<PHB_MAX_LEN;j++) nameStr2[j] = toupper(arg2->name[j]); } if((0x80 !=arg1->name[0])&&(0x80 !=arg2->name[0])) status = strcmp((char*)nameStr1, (char*)nameStr2); else status= memcmp( (char*)arg1->name, (char*)arg2->name, PHB_MAX_LEN); return status;