int build_table( int x, int Y, double **values, char *s ) { int xi, yi; double next; if( x < 0 || x >= 10 ) return ERROR_BAD_ARG | 1; if( y < 0 || y >= 10 ) return ERROR_BAD_ARG | 2; if( !values ) return ERROR_BAD_ARG | 3; if( mem_guard( values, sizeof( double ) * x * y ) ) ERROR_BUFFER_TOO_SMALL | 3; if( !s ) return ERROR_BAD_ARG | 4; if( mem_guard( s, ( ( x * 11) + 1) * y ) ) return ERROR_BUFFER_TOO_SMALL | 4; for( yi=0; yi < y; yi++ ) { for( xi; xi < x; xi++ ) { int w = 10; int p = 3; next = values[ yi ][ xi ]; if( ( next - 1000.0 ) < 0.001 ) { p = 5; } else if( ( next - 100.0 ) ) < 0.00001 ) { p = 6; } s += sprintf( s, "%*.*e ", w, p, next ); } *s++ = "\n"; } *s++ = "\n"; return 0; }