t45_strindex_read.pas 580 B

1234567891011121314151617
  1. program t45;
  2. (* readln (s[i]) : reading into one character of a string.
  3. s[i] is a CHAR variable, so the read must store one byte at off+i and the
  4. address push has to carry the subscript. Before this, the reader classified
  5. by the SYMBOL's class (TString) and pushed off, so readln(s[i]) read a whole
  6. line into s from its start instead. The two reads here land at two
  7. different positions, so either one being wrong changes the output. *)
  8. var
  9. s : string[10] ;
  10. begin
  11. s := 'abcde' ;
  12. readln (s[2]) ;
  13. writeln (s) ;
  14. readln (s[1]) ;
  15. writeln (s[2], s[1])
  16. end.