diff options
Diffstat (limited to 'minie')
-rw-r--r-- | minie/e2c.c | 6 | ||||
-rw-r--r-- | minie/test9.e | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/minie/e2c.c b/minie/e2c.c index baaa1b8..e2388b7 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -727,6 +727,7 @@ static void prologue( void ) emitLn( "#include <stdio.h>" ); emitLn( "#include <stdlib.h>" ); emitLn( "#include <string.h>" ); + emitLn( "int getc_wrapper( void ) { int c = getc( stdin ); if( c == EOF ) return '\\0'; else return c; }" ); register_internal_functions( ); register_internal_constants( ); @@ -958,7 +959,8 @@ static void assignment( void ) /* right hand side, any expression */ expression( ); if( type.type == TYPE_ARRAY && type.details.array.type->type == TYPE_CHAR ) { - emit( ", %d )", type.details.array.len ); + emit( ", %d ); ", type.details.array.len ); + emit( "%s[%d-1] = '\\0'", varName, type.details.array.len ); } emitLn( ";" ); } @@ -1039,7 +1041,7 @@ static void parameterList( void ) Expect( S_lparen ); if( sym == S_rparen ) { if( strcmp( funcName, "system.readchar" ) == 0 ) { - emit( "getc( stdin )" ); + emit( "getc_wrapper( )" ); sym = getSym( ); return; } diff --git a/minie/test9.e b/minie/test9.e index c625bce..9b087dd 100644 --- a/minie/test9.e +++ b/minie/test9.e @@ -19,6 +19,7 @@ begin i := i + 1; c := system.readchar( ) end; + s[i] := char( 0 ); d := s; system.writeline( d ); end |