I am writing a basic qsort
to sort an array of strings. What I have so far is:
int scmp(const void *p1, const void *p2)
{
const char* s1 = p1;
const char* s2 = p2;
// ...
}
int main(void)
{
char* strings[] = {"Onus", "deacon", "Alex", "zebra"};
qsort(strings, sizeof(strings), sizeof(*strings), scmp);
}
Note that above the sizeof(strings)
gives me 32 (4 pointers), whereas what I want is sizeof(strings)/sizeof(*strings)
. This fixes the issue, but I'm curious what the "stack smashing" means and how that occurs?