linux - Some daze about the Pascal output -
platform: linux 2.6.18 x86_64
compiler: free pascal compiler version 2.2.2 [2008/11/05] x86_64
the source code is:
program main; var invalue:string; begin (*until eof, loop continue work*) while not eof begin write('please input express: '); flush(stdout); readln(invalue); writeln('the expression is: ',invalue); end; writeln(''); writeln('exit program. bye!'); end.
i compiled , run it. ouput like:
123 please input express: expression is: 123 234 please input express: expression is: 234 345 please input express: expression is: 345 exit program. bye!
the numbers input. googled it, , thought because of buffer. tried add flush(stdout) or flush(output) after write. still not work well.
i hope works as:
please input express: 123 expression is: 123 please input express: 234 expression is: 234 please input express: 345 expression is: 345 exit program. bye!
thank you! , sorry fool~
addition: tried (thank you, aloush!)
program main; var invalue:string; begin (*until eof, loop continue work*) while not eof begin write('please input express: '); flush(stdout); readln(invalue); writeln('') writeln('the expression is: ',invalue); end; writeln(''); writeln('exit program. bye!'); end.
the result still not as:
1 please input express: expression is: 1 2 please input express: expression is: 2 3 please input express: expression is: 3 4 please input express: expression is: 4 5 please input express: expression is: 5 exit program. bye!
the readln still executed before first write.
by way, tries:
program main; var invalue:string; begin (*until eof, loop continue work while not eof begin*) repeat write('please input express: '); flush(stdout); readln(invalue); writeln('the expression is: ',invalue); until eof; writeln(''); writeln('exit program. bye!'); end.
in case, first loop good, others still wrong.
please input express: 123 expression is: 123 234 please input express: expression is: 234 345 please input express: expression is: 345 exit program. bye!
thank you!
final solution: http://www.amath.unc.edu/sysadmin/doc4.0/pascal/lang_ref/ref_io.doc.html#592 it's because, eof corresponds implicit read. current code should be:
program main; var invalue:string; begin (*until eof, loop continue work*) write('please input express: '); while not eof begin readln(invalue); writeln('the expression is: ',invalue); write('please input express: '); end; writeln(''); writeln('exit program. bye!'); end.
lastly, thank you, aloush here , keiy on csdn!
can try following?
program main; var invalue:string; begin (*until eof, loop continue work*) while not eof begin write('please input express: '); flush(stdout); readln(invalue); writeln('') writeln('the expression is: ',invalue); end; writeln(''); writeln('exit program. bye!'); end.
Comments
Post a Comment