/* ECP: FILEname=fig9_31.c */ /* 1*/ #include "table.h" /* 2*/ #define StrConv1( Len ) ( "%" #Len "s" ) /* 3*/ #define StrConv( Len ) ( StrConv1( Len ) ) /* 4*/ ShapeType * /* 5*/ ReadShape( void ) /* 6*/ { /* 7*/ static char InputString[ MaxStringLen + 1 ]; /* 8*/ ShapeSwitch *Ptr; /* 9*/ ShapeType *Shape; /*10*/ printf( "Enter shape type: " ); /*11*/ if( scanf( StrConv( MaxStringLen ), InputString ) == 1 ) /*12*/ for( Ptr = ShapeTable; Ptr->ShapeName; Ptr++ ) /*13*/ if( strcmp( Ptr->ShapeName, InputString ) == 0 ) /*14*/ { /* Found The Type */ /*15*/ if( Shape = ( *Ptr->ReadShape )( ) ) /*16*/ Shape->TheShape = Ptr - ShapeTable; /*17*/ return Shape; /*18*/ } /*19*/ return NULL; /* No Match */ /*20*/ } /*21*/ void /*22*/ WriteShape( const ShapeType * Shape ) /*23*/ { /*24*/ printf( "Shape is a %s ", /*25*/ ShapeTable[ Shape->TheShape ].ShapeName ); /*26*/ ( *ShapeTable[ Shape->TheShape ].WriteShape )( Shape ); /*27*/ printf( "; the area is %.2f\n", Shape->Area ); /*28*/ } /*29*/ void /*30*/ AreaShape( ShapeType * Shape ) /*31*/ { /*32*/ ( *ShapeTable[ Shape->TheShape ].Area )( Shape ); /*33*/ }