Generic array manipulation routine
Roger A. Hurwitz
hurwitz at enuxha.eas.asu.edu
Tue Jan 29 09:18:51 AEST 1991
Hello, Cpersons;
I was hoping for some help on how to write a single C function
for manipulating arrays, that can be called without change for
arrays with elements of differing types. For example, the
qsort() function I use in Borland's Turbo C seems to do this.
Borland's qsort() has the following syntax;
void qsort (void *base, size_t nelem, size_t width,
int (*fcmp) (const void *, const void *));
Where _base_ is a pointer to the 0th element in the array, _nelem_
is the number of elements in the array, and _width_ is the size
in bytes of each array element. Given these parameters, I suppose
one could cast the void pointer to a char pointer and manipulate
the elements byte-by-byte, but I was wondering if there is a "better"
approach.
Thanks in advance for any help,
Roger Hurwitz
hurwitz at enuxha.eas.asu.edu
More information about the Comp.lang.c
mailing list