home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!mucs!lucs!scst81
- From: scst81@csc.liv.ac.uk (Mr. I. Rowland)
- Newsgroups: comp.lang.c
- Subject: Use of ANSI qsort
- Keywords: qsort
- Message-ID: <C19KrI.M9A@compsci.liverpool.ac.uk>
- Date: 22 Jan 93 16:35:41 GMT
- References: <C0pBDG.7Ky@news2.cis.umn.edu> <1993Jan12.024932.27939@organpipe.uug.arizona.edu>
- Sender: news@compsci.liverpool.ac.uk (News Eater)
- Organization: Computer Science, Liverpool University
- Lines: 62
- Nntp-Posting-Host: irw.csc.liv.ac.uk
-
- I am using the ANSI function qsort to sort an array of structs. The struct is as follows :
-
-
-
- struct clast_item{
- int rank, a,b,c;
- double tnd_mm, tnd_phi, sphericity;
- float ab_ratio, flatness_index, volume, area;
- int roundness;
- char lithology[2];
- char zing;
- };
-
- The sorting key is lithology and the qsort function is called in the following routine:
-
- void sort_tnds(void)
- {
- qsort((char *) clast_record,
- (unsigned) num_records,
- sizeof(struct clast_item),lithology_compare);
- }
-
-
- The lithology_compare function is as follows :
-
- int lithology_compare (struct clast_item *a, struct clast_item *b)
-
- {
-
- return strcmp(a->lithology,b->lithology);
- }
-
- When the code is compiled in its host program under UNIX the following warnings are declared :
-
- warning 604: Pointers are not assignment-compatible.
- warning 563: Argument #4 is not the correct type.
-
- The program works i.e. the array is sorted correctly, but I would like to eliminate the warnings.
-
-
- I also have a similar problem that uses tnd_mm as the sorting key : the compare function is :
-
- int tnd_compare (struct clast_item *a, struct clast_item *b)
-
- {
-
- double tnd1 = a->tnd_mm;
- double tnd2 = b->tnd_mm;
-
-
- if (tnd1 > tnd2 ) return (-1);
- if (tnd1 == tnd2) return (0);
- else return(1);
- }
-
- Any help would be gratefully appreciated.
-
- Frustratingly
-
- Ian Rowland
-
- P.S. Thanks to all of you that helped me with the MALLOC and REALLOC functions.
-