Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!ukma!sean From: sean@ms.uky.edu (Sean Casey) Newsgroups: comp.unix.wizards Subject: Why doesn't this qsort example work? Message-ID: <7527@g.ms.uky.edu> Date: Mon, 19-Oct-87 03:21:45 EDT Article-I.D.: g.7527 Posted: Mon Oct 19 03:21:45 1987 Date-Received: Tue, 20-Oct-87 01:05:55 EDT Organization: The Leaning Tower of Patterson Office @ The Univ. of KY Lines: 41 Keywords: argh, frustration, core dump I'm trying to use qsort(3) for the first time and I'm having a bit of trouble. I've included some code here that reproduces the problem. The following C program coredumps because compar() is being called with bogus arguments. I'm sure it's my fault, but I just can't seem to see what I'm doing wrong. Maybe one of you can tell me: struct tstr { int a; int b; }; compar(x, y) struct tstr *x, *y; { if (x->a < y->a) /* coredumps here, therefore a or b is bogus */ return(-1); /* a < b */ if (x->a > y->a) return(1); /* a > b */ return(0); /* a = b */ } main() { struct tstr t[2]; t[0].a = 1; t[1].a = 2; /* this sorts t[] by the "a" field */ qsort(&t[0], 2, sizeof(struct tstr), (*compar)()); } Thanks for any light you can shed, Sean -- -- Sean Casey sean@ms.uky.edu, {rutgers,uunet,cbosgd}!ukma!sean -- (the Empire guy) sean@ms.uky.csnet, sean@UKMA.BITNET -- "Have fun storming the castle!" - Miracle Max