home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / interpre / p_pascal / samples / strings.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-02-14  |  1.2 KB  |  37 lines

  1. (*$c+*)
  2. PROGRAM string_test(input,output,prr,prd);
  3. { String constants can be up to 80 characters long: }
  4. CONST z = '                               ';
  5. VAR x : ARRAY[1 .. 32] OF CHAR;
  6.     i : INTEGER;
  7.     prr, prd : TEXT;
  8. {Input and Output are predeclared Pascal text files. }
  9. BEGIN
  10. {Demonstrating how to declare external text files:
  11.  In this implementation, prr and prd are named in the
  12.  PROGRAM line, so the command line must include files
  13.  with "prr" and "prd" AS A PART of their path-names.
  14.  Thus, the command line files:
  15.   a:\xxx\prr
  16.  and
  17.   c:prd.zzz
  18.  will be interpreted by this system as valid "external"
  19.  prr and prd files.
  20.  Pascal external files are opened in C "r+" mode if
  21.  they exist, else C "w+" mode.}
  22.   REWRITE(prr); REWRITE(prd);
  23.   WRITELN(prr,'PRR: 12345671234567');
  24.   WRITELN(prd,'PRD: 1234567812345678');
  25.   RESET(prr); RESET(prd);
  26.   {NOTE THAT "x := z" BELOW IMPLIES MOVING A STRING
  27.    CONSTANT INTO A PASCAL CHARACTER ARRAY:}
  28.   x := z; i := 1;
  29.   WHILE (i < 33) AND NOT EOLN(prr) DO
  30.    BEGIN READ(prr, x[i]); i := i + 1 END;
  31.   FOR i := 1 TO 32 DO WRITE(x[i]); WRITELN;
  32.   x := z; i := 1;
  33.   WHILE (i < 33) AND NOT EOLN(prd) DO
  34.    BEGIN READ(prd, x[i]); i := i + 1 END;
  35.   FOR i := 1 TO 32 DO WRITE(x[i]); WRITELN
  36. END.
  37.