Chris said:
I have no problem with that. But it makes `print` recursive,
and hence disallowed by the original specification.
Must print() call qsort() to itself? Couldn't it call a different
function?
#include <stdio.h>
#include <stdlib.h>
static int mymax; /* Specs didn't say "no global variables" */
int print(const void *a, const void *b) {
static int current = 0;
if (current < mymax) printf("%d\n", ++current);
return 0;
}
void doit(int i) {
void *ptr = malloc(i+1); /* Should have test for failure */
mymax = i;
qsort(ptr,mymax+1,1,print);
free(ptr);
}
int main(int argc, char *argv[]) {
int val;
sscanf(argv[1], "%d", &val);
doit(val);
return 0;
}
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>