/* ECP: FILEname=fig9_32.c */ /* 1*/ #include "shape.h" /* 2*/ /* Comparison Function For qsort */ /* 3*/ int /* 4*/ Compare( const void *Left, const void *Right ) /* 5*/ { /* 6*/ ShapeType *LeftShape = * ( ShapeType ** ) Left; /* 7*/ ShapeType *RightShape = * ( ShapeType ** ) Right; /* 8*/ if( LeftShape->TheShape < RightShape->TheShape ) /* 9*/ return -1; /*10*/ else /*11*/ if( LeftShape->TheShape > RightShape->TheShape ) /*12*/ return 1; /*13*/ /* Same Shape */ /*14*/ if( LeftShape->Area < RightShape->Area ) /*15*/ return -1; /*16*/ else /*17*/ if( LeftShape->Area > RightShape->Area ) /*18*/ return 1; /*19*/ else /*20*/ return 0; /*21*/ } /*22*/ /* Read Some Shapes, Sort Them By Area, And Write Them Out */ /*23*/ #define MaxShapes 1000 /*24*/ main( void ) /*25*/ { /*26*/ ShapeType *Shapes[ MaxShapes ]; /*27*/ int ItemsRead, i; /*28*/ for( ItemsRead = 0; ItemsRead < MaxShapes; ItemsRead++ ) /*29*/ if( ( Shapes[ ItemsRead ] = ReadShape( ) ) == NULL ) /*30*/ break; /*31*/ else /*32*/ AreaShape( Shapes[ ItemsRead ] ); /*33*/ printf( "\n" ); /*34*/ qsort( Shapes, ItemsRead, sizeof( ShapeType * ), Compare ); /*35*/ for( i = 0; i < ItemsRead; i++ ) /*36*/ WriteShape( Shapes[ i ] ); /*37*/ return 0; /*38*/ }