Here is a program I wrote to construct a suffix array.
Code:
int pstrcmp(const void* str1, const void* str2){
int tmp = strcmp((char*)str1, (char*)str2);
return tmp;
}
int main(){
char str[]="to be or not to be this is a problem.";
char **a = (char**) malloc(sizeof(char*)*strlen(str));
for(int i=0;i<strlen(str);i++){
a[i] = &str[i];
}
qsort(a,strlen(str),sizeof(char*),pstrcmp);
for(int i=0;i<strlen(str);i++) cout<<a[i]<<endl;
return 0;
}
It seems pstrcmp doesn't work.... When I debug the pstrcmp, the tmp value is always -1! Anybody knows what's wrong?