could someone explain this function to me better. Especially the last argument thanx.
could someone explain this function to me better. Especially the last argument thanx.
http://developer.apple.com/documenta...l/qsort.3.html
The last argument is a pointer to a function which returns certain number depending on how you want the list sorted. the function takes 2 arguments, two things from the list, the function will compare them then return the values accordingly, depending on how you write the function. Usually, people just return an strcmp() of the two values.
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
Maybe if they are strings.Usually, people just return an strcmp() of the two values.
The compare functions takes in two const void pointers. As such you have to cast them to variables and then compare.
so the prototype would be something like thisthen you would use it like so.Code:int compare(const void *num1,const void *num2);thank youCode:qsort((void*)buffer,strlen(buffer),sizeof buffer,(void *)compare);
>(void*)buffer
No cast is needed to convert a pointer-to-T to a pointer-to-void.
>(void *)compare
A function pointer and a void pointer are not the same, this cast is dangerous and quite unnecessary since you can only do two things with a function, call it and take its address. If you aren't calling it then you must be taking its address and all is well as long as the type of the function pointers match.
My best code is written with the delete key.