Cpp Dev Programming Forum

Cpp Programming


#1 Today

DarkVader

Guest

How to use qsort?

I have a problem with "qsort" function included in the <stdlib.h>

Code:

# include <stdio.h>
# include <stdlib.h>

int numcomp(int*, int*);

struct a {
    int s [max];
    int x ;
};
  

int main(){
........
........
/*Where  (void**)(p->s) is a int array,
max is dimension of array, 
sizeof(int) indicate size of array element,
(int(*)(void*,void*))numcomp) is a pointer to function "numcomp" that return a "int" and it have how parameters (int*,int*).*/

qsort((void**)(p->s),max,sizeof(int),(int(*)(void*,void*))numcomp);

return 0;

}

Now the compiler get me this error :

" Description Resource Path Location Type
passing argument 4 of ‘qsort’ from incompatible pointer type sort.c /struct line 63 C/C++ Problem "

Why? Help me, please.

p.s. I used for compiler this program Eclipse (Cygwin) on Windows 7.

#2 Today

dave79

Guest

Re: How to use qsort?

The prototype for the standard C library function qsort() is

Code:

 void qsort(void *base, size_t nmemb, size_t size,
                  int(*compar)(const void *, const void *));

To avoid the compiler complaint, make the cast on the fourth argument match the prototype exactly. Note that const void * is not the same as void *. This is important to the compiler, and should be important to you.


If you declare the function properly, you don't need a cast when you call it. In a code review, when I see a program with casts where they shouldn't be needed, it's a red flag for me. I mean, it's not necessarily "wrong" to put a cast even if you don't need it, but casting can hide problems that otherwise might have been detected by the compiler. See Footnote.

#3 Today

cheap beads

Guest

Re: How to use qsort?

This blog need to be quick. Seek to keep turquoiseblue tigers eye beads clear of temperature preceding 85 P oker. A bit more include an excessive amount issues on this except ones turquoise is usually stashed next to some sort of water heater. Being exposed to help excessive coral beadstemperature the moment within a violet moon need not have an impact on this jewel an excessive amount, although frequent subjection is usually a mindblowing. Suppliers on flea promotes in addition to indicates are large hole glass beadsspecifically liable to that. When i the moment attained some sort of turquoise dealership of which shed many cash considering that the warm transformed his or her turquoise some sort of weak colour connected with magenta. When you advertise outdoors, keep turquoise shaded on the solar. Tend not to place ones turquoise available within a garden shed exceptwholesale jewelry it truly is fresh air trained or maybe yourr home is a very nice local weather.On the similar wrinkles, tend not to retail store turquoise having trickier products; any sort of nudge or maybe vibration causes this drops to help scrape up against the different subject matter. When you retail store ones turquoise ring having lots of different bracelets, avoid getting Glass Beadsstunned to help hang it on and find a lot of very little scores marring this even develop. An alternative way to retail store turquoise is usually to invest in cardboard treat cardboard boxes. There're low cost, and in addition they include underlay.

#4 Today

encxiek

Guest

Re: How to use qsort?

Volvi a "perdonar" otra vez el Atltico en el minuto 59, tras un barcelona camisetas  saque de esquina y nuevo barullo con baln a las nubes  tienda real Madrid de Domnguez.

Pero el fruto lleg a los 63 minutos, en nuevo ataque sobre el marco de Fabricio, con dejada perfecta  Camiseta de la selección de Polonia de Falcao, de cabeza, para que Koke remachara de potente remate.

Board footer

RSS
Powered by PunBB
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi


Darmowe Forum | Ciekawe Fora | Darmowe Fora
www.lksorzelwysoka.pun.pl www.mobileinfantry.pun.pl www.tibiacc.pun.pl www.sonyericsson4ever.pun.pl www.vsmarbar.pun.pl