sotring/comparing strings
-
Hi to all. I'm trying to sort strings which contains some eastern European specific letters. I'm sorting with qsort function:
qsort( (void *)polje, (size_t)cnt, sizeof( char * ), compare );
where 'compare' is a helper functionint compare( const void *arg1, const void *arg2 )
which uses '_stricoll' function. Wen running my test app sorting doesn't work. I then tried to set local settings like this on OnInitDialog():char\* locale; locale = setlocale(LC\_ALL,"Croatian");
locale returns "Croatian_Croatia.1250"; but sorting still isn't working, why? Thanks in advance
-
Hi to all. I'm trying to sort strings which contains some eastern European specific letters. I'm sorting with qsort function:
qsort( (void *)polje, (size_t)cnt, sizeof( char * ), compare );
where 'compare' is a helper functionint compare( const void *arg1, const void *arg2 )
which uses '_stricoll' function. Wen running my test app sorting doesn't work. I then tried to set local settings like this on OnInitDialog():char\* locale; locale = setlocale(LC\_ALL,"Croatian");
locale returns "Croatian_Croatia.1250"; but sorting still isn't working, why? Thanks in advance
All I can suggest is splitting the problem into smaller parts. First, check that
_stricoll
(and thus your compare function) compare strings as you would expect. After that...well, can you confirm thatpolje
is of typechar* polje[]
, i.e. an array of character pointers?Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
All I can suggest is splitting the problem into smaller parts. First, check that
_stricoll
(and thus your compare function) compare strings as you would expect. After that...well, can you confirm thatpolje
is of typechar* polje[]
, i.e. an array of character pointers?Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thanks for replay, code:
CString \*polje = new CString\[cnt\]; for(int i=0; i<cnt;i++) { CString pom; m\_List.GetText(i,pom); polje\[i\] = pom; } qsort( (void \*)polje, (size\_t)cnt, sizeof( char \* ), compare );
I have a list box control where user can add strings for sorting. Posted code is extracted from OnOK()!
-
Thanks for replay, code:
CString \*polje = new CString\[cnt\]; for(int i=0; i<cnt;i++) { CString pom; m\_List.GetText(i,pom); polje\[i\] = pom; } qsort( (void \*)polje, (size\_t)cnt, sizeof( char \* ), compare );
I have a list box control where user can add strings for sorting. Posted code is extracted from OnOK()!
Right...well, that
sizeof(char*)
in theqsort
call isn't going to be correct, is it? I would suggest:- Change compare so it expects its two parameters to be pointers to
CString
- Change the
sizeof( char* )
to besizeof( CString )
And here's a thought - if you used STL containers, you could use type-safe algorithms and things that would highlight these issues...
std::vector polje(cnt);
for(int i=0; i<cnt;++cnt)
{
CString pom;
m_List.GetText(i,pom);
polje.push_back(pom);
}
std::sort(polje.begin(), polje.end(), compareFunction);Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
- Change compare so it expects its two parameters to be pointers to
-
Hi to all. I'm trying to sort strings which contains some eastern European specific letters. I'm sorting with qsort function:
qsort( (void *)polje, (size_t)cnt, sizeof( char * ), compare );
where 'compare' is a helper functionint compare( const void *arg1, const void *arg2 )
which uses '_stricoll' function. Wen running my test app sorting doesn't work. I then tried to set local settings like this on OnInitDialog():char\* locale; locale = setlocale(LC\_ALL,"Croatian");
locale returns "Croatian_Croatia.1250"; but sorting still isn't working, why? Thanks in advance
josip cagalj wrote:
Wen running my test app sorting doesn't work.
For anything or just eastern European specific letters.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
josip cagalj wrote:
Wen running my test app sorting doesn't work.
For anything or just eastern European specific letters.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
Just eastern European letters.