home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20096 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.9 KB  |  76 lines

  1. Path: sparky!uunet!mcsun!uknet!mucs!lucs!scst81
  2. From: scst81@csc.liv.ac.uk (Mr. I. Rowland)
  3. Newsgroups: comp.lang.c
  4. Subject: Use of ANSI qsort
  5. Keywords: qsort
  6. Message-ID: <C19KrI.M9A@compsci.liverpool.ac.uk>
  7. Date: 22 Jan 93 16:35:41 GMT
  8. References: <C0pBDG.7Ky@news2.cis.umn.edu> <1993Jan12.024932.27939@organpipe.uug.arizona.edu>
  9. Sender: news@compsci.liverpool.ac.uk (News Eater)
  10. Organization: Computer Science, Liverpool University
  11. Lines: 62
  12. Nntp-Posting-Host: irw.csc.liv.ac.uk
  13.  
  14. I am using the ANSI function qsort to sort an array of structs. The struct is as follows :
  15.  
  16.  
  17.  
  18. struct clast_item{
  19.                     int rank, a,b,c;
  20.                     double tnd_mm, tnd_phi, sphericity;
  21.                     float ab_ratio, flatness_index, volume, area;
  22.                     int roundness;
  23.                     char lithology[2];
  24.                     char zing;
  25.                  };
  26.  
  27. The sorting key is lithology and the qsort function is called in the following routine:
  28.  
  29. void sort_tnds(void)
  30. {
  31. qsort((char *) clast_record,
  32.         (unsigned) num_records, 
  33.         sizeof(struct clast_item),lithology_compare);
  34. }
  35.  
  36.  
  37. The lithology_compare function is as follows :
  38.  
  39. int lithology_compare (struct clast_item *a, struct clast_item *b)
  40.  
  41. {
  42.  
  43.     return strcmp(a->lithology,b->lithology);
  44. }
  45.  
  46. When the code is compiled in its host program under UNIX the following warnings are declared :
  47.  
  48. warning 604: Pointers are not assignment-compatible.
  49. warning 563: Argument #4 is not the correct type.
  50.  
  51. The program works i.e. the array is sorted correctly, but I would like to eliminate the warnings. 
  52.  
  53.  
  54. I also have a similar problem that uses tnd_mm as the sorting key : the compare function is :
  55.  
  56. int tnd_compare (struct clast_item *a, struct clast_item *b)
  57.  
  58. {
  59.  
  60.     double tnd1 = a->tnd_mm;
  61.     double tnd2 = b->tnd_mm;
  62.     
  63.  
  64.     if (tnd1 > tnd2 ) return (-1);
  65.     if (tnd1 == tnd2) return (0);
  66.     else return(1);
  67. }
  68.  
  69. Any help would be gratefully appreciated.
  70.  
  71. Frustratingly
  72.  
  73. Ian Rowland
  74.  
  75. P.S. Thanks to all of you that helped me with the MALLOC and REALLOC functions.
  76.