/* ECP: FILEname=fig8_30.c */ /* 1*/ void /* 2*/ PrintSpaces( int HowMany ) /* 3*/ { /* 4*/ while( HowMany-- > 0 ) /* 5*/ putchar( ' ' ); /* 6*/ } /* 7*/ void /* 8*/ PutOut( const char Line[ ], int Length ) /* 9*/ { /*10*/ int SmallGapLen; /*11*/ int NumGaps = 0; /*12*/ int NumSmallGaps; /*13*/ int LineLen = strlen( Line ); /*14*/ int TotalSpaces; /*15*/ int i; /*16*/ for( i = 0; Line[ i ]; i++ ) /*17*/ if( Line[ i ] == ' ' ) /*18*/ NumGaps++; /*19*/ if( !NumGaps ) /*20*/ { /*21*/ puts( Line ); /*22*/ return; /*23*/ } /*24*/ TotalSpaces = Length - LineLen + NumGaps; /*25*/ SmallGapLen = TotalSpaces / NumGaps; /*26*/ NumSmallGaps = NumGaps - TotalSpaces % NumGaps; /*27*/ for( i = 0; Line[ i ]; i++ ) /*28*/ if( Line[ i ] == ' ' ) /*29*/ PrintSpaces( SmallGapLen + ( NumSmallGaps-- <= 0 ) ); /*30*/ else /*31*/ putchar( Line[ i ] ); /*32*/ putchar( '\n' ); /*33*/ }