[plug] Fw: qsort

James Elliott James.Elliott at wn.com.au
Mon Jun 10 17:31:05 WST 2002


Sorry, this went to the wrong address - should have gone to Murdoch.

James Elliott
Ravensthorpe Computers
ABN 34 305 232 710
Tel:   08 9838 1043
Fax:  08 9838 1049
Cell:  0428 39 6052
E-mail:  James.Elliott at wn.com.au
Australia Post:
PO Box 228, Ravensthorpe WA 6346
----- Original Message -----
From: "James Elliott" <James.Elliott at wn.com.au>
To: <plug at plug.linux.org.au>
Sent: Monday, June 10, 2002 4:56 PM
Subject: [plug] Fw: qsort


> Thanks Christian
>
> Actually, I have been playing arund with it since yesterday, and I think I
> have it almost worked out:
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <sys/types.h>
> #include <unistd.h>
> #include <sys/stat.h>
>
> int main (int argc, char *argv[])
> {
>    struct stat statbuf;
>
>    stat (argv[1], &statbuf);
>
>    printf ("\nFOR FILE %s\n", argv[1]);
>    printf ("Last time accessed: %s\n", statbuf.st_atime);   // ???
>
>    return 0;
> }
>
> but the line I have marked with "???" prints gibberish after the "Last
time
> ..." string and when it comiles it give a warning suggesting I have either
a
> format or pointer problem.  I suspect that what I am trying to print is
not
> a %s string .... is that the problem
>
> James Elliott
>
> ----- Original Message -----
> From: "Christian" <christian at it.murdoch.edu.au>
> To: "James Elliott" <James.Elliott at wn.com.au>
> Sent: Monday, June 10, 2002 3:40 PM
> Subject: Re: qsort
>
>
> > On Sun, Jun 09, 2002 at 12:21:01PM +0800, James Elliott wrote:
> > > I have read the man page for the qsort function, but I must be
> > > misinterpreting something because I keep getting parse error messages.
> > > I would be obliged if you could reply with an example using the qsort
> > > command.
> >
> > I think you should be able to find some if you do a search of the
> > Internet.  To create a full example would just take too long right now.
> >
> > In general though qsort() is not hard to use.  It just points an array
> > of items of which the first argument is a pointer to the beginning, the
> > second element is the number of items in the array and the third item is
> > the size of each array element.  Note you can get this by calling
> > sizeof(type) where "type" is the array element type.
> >
> > The final argument is the name of a function which performs a comparison
> > operation between two items in the list.  The manual page describes the
> > values this must return.  This is the beauty of the qsort function
> > because it allows you to apply a well-written, fully-debugged and
> > efficient implementation of an excellent sorting algorithm to virtually
> > any data type.  Want to search an array of ints?  Easy.  Floats?
> > Simple!  Some arbitrary complex data structure?  Well, if you
> > can write the comparion function then qsort can do the rest.
> >
> > Regards,
> >
> > Christian.
> >
> > --
> > DSA 0x2A0F80F3: 39F3 4E10 9BE9 E728 A9EE  029C D51D EE53 2A0F 80F3
> >
>
>
>
>




More information about the plug mailing list