Hi guys, if I do this everything works fine:
However, I like to allocate my strings like this (filenames example):
Please help. Thank you.
Edit: Guys, I fixed it:
Thanks
Code:
char* strings[]={"Zorro", "Alex", "Celine", "Bill", "Forest", "Dexter"};
qsort(strings, 6, sizeof(char*), cmp_func);Code:
// allocate
char** mem=new char*[n]; // allocate pointers
mem[0]=new char[n*MAX_PATH]; // allocate memory
// set pointers
for(int i=1; i<n; i++){
mem[i]=mem[i-1]+MAX_PATH;
}
// fill in strings
...
// sort causes debug assertion failure _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
qsort(mem, n, sizeof(char*), cstring_cmp);Edit: Guys, I fixed it:
Code:
// instead of allocating the memory like this...
mem[0]=new char[n*MAX_PATH];
// ...it's better to do it this way (with a new variable) so the pointer won't get shuffled
char* buffer=new char[n*MAX_PATH];