[comp.lang.pascal] Problems with Read Procedure

GRAD205%BRFUEM.BITNET@uicvm.uic.edu ( Humberto) (05/20/91)

Greetings ...

I don't know the reason ... But, the following source piece doesn't work:

Program Test;
uses crt;
var
    Name  : string[12];
    Field : array[1..10] of string[10];
    n     : integer;
begin
    ClrScr;
    Read(Name);
    n := 1;
    repeat
       Read(Field[n]);
       n := n + 1;
    until n = 11;
end.

Well, this program doesn't have errors at compilation ... But when I run it,
Only Name and Field[1] are read, Field[2], Field[3], ..., Field[10]  no  ...
What is happening? Please, could someone help me?

Oh, yes. I'm using Turbo Pascal 5.5.

Thanks very much in advance.

Humberto

+----------------------------+----------------------------------------------+
|  Alunos da graduacao do    | E-MAIL: BITNET= GRAD205@BRFUEM.BITNET        |
|  Curso de Matematica       |           ANSP= GRAD205@BRFUEM.ANPR.BR       |
|  BRFUEM                    |                 GRAD205@NPDVM1.FUEM.ANPR.BR  |
+----------------------------+----------------------------------------------+
|  Fundacao Universidade Estadual de Maringa - FUEM                         |
|  Departamento de Matematica - DMA                                         |
|  Telefax: (0442) 22-2754                                                  |
+---------------------------------------------------------------------------+

KHOFMANN@cipvax.biolan.Uni-Koeln.DE (Kay Hofmann) (05/21/91)

In <26937@adm.brl.mil> GRAD205%BRFUEM.BITNET@uicvm.uic.edu writes:

> I don't know the reason ... But, the following source piece doesn't work:
> 
> Program Test;
> uses crt;
> var
>     Name  : string[12];
>     Field : array[1..10] of string[10];
>     n     : integer;
> begin
>     ClrScr;
>     Read(Name);             <----------------------------
>     n := 1;
>     repeat
>        Read(Field[n]);
>        n := n + 1;
>     until n = 11;
> end.
> 
> Well, this program doesn't have errors at compilation ... But when I run it,
> Only Name and Field[1] are read, Field[2], Field[3], ..., Field[10]  no  ...
> What is happening? Please, could someone help me?

Supposing you wnat to enter seval strings and put them into field [1..10]
each string into one array element, you should use READLN instead of READ
because PASCAL otherwise starts filling field[1] and should issue an error-
message if field[1] has maximum length and further input occurs.
(CR and LF are interpreted as part of field[1])
Bye,
     Kay

hoffmann@infopls.chi.il.us (Robert Hoffmann) (05/22/91)

GRAD205%BRFUEM.BITNET@uicvm.uic.edu ( Humberto) writes:

> var
> begin
>     ClrScr;
>     Read(Name);
>     n := 1;
>     repeat
>        Read(Field[n]);
>        n := n + 1;
>     until n = 11;
> end.
> 
> Well, this program doesn't have errors at compilation ... But when I run it,
> Only Name and Field[1] are read, Field[2], Field[3], ..., Field[10]  no  ...
> What is happening? Please, could someone help me?
 
I suspect it's your use of the Read() function.
 
Read stops at the first CR/LF combination it finds... and won't continue 
until you clear the CR/LF out.
 
Suggest changing the Read() to ReadLn() and testing it that way.
 
Rob
--------------------------------
hoffmann@infopls.chi.il.us