/**************************************************** SUBROUTINE COMPAREM2 COMPAREM3 IS USED BY QSORT AS A GUIDE TO SORT AN ARRAY OF THREE INTEGER STRUCTURES BY THEIR FIRST VALUE AND SECOND VALUES. IF A RETURNED VALUE IS -1, THE POSITION OF THE TWO COMPARED PARAMETERS IS SWITCHED. IF THE RETURNED VALUE IS 0 OR 1, NOTHING IS DONE. *******************************************************/ int comparem3( const void *e1, /* FIRST VALUE TO COMPARE */ const void *e2 /* SECOND VALUE TO COMPARE */ ) { /**************************************************** I - RETURNED VALUE: -1 IF E1 < E2 or E1 = E2 && E1.second < E2.second 0 IF E1 = E2 and E1.second <= E2.second 1 IF E1 > E2 or E1 = E2 && E1.second > E2.second *****************************************************/ int i = 0; int eonenum = ((struct write3 *)e1)->num; int etwonum = ((struct write3 *)e2)->num; int eonerec = ((struct write3 *)e1)->rec; int etworec = ((struct write3 *)e2)->rec; if ( eonenum < etwonum ) i = -1; else if ( eonenum > etwonum ) i = 1; else if ( eonenum == etwonum ) { if ( eonerec < etworec ) i = -1; else if ( eonerec > etworec ) i = 1; } return i; }