pizzapablo
pizzapablo

Reputation: 107

Error while giving type of string in Pascal

I am defining a new string type in my pascal code after Program filename and before variables, but it is giving an error 'Begin' expected Str20 found.

Program Input_try_1;

Type Str20 : string[20];

Var f: file of Str20;
    x : String;
    EOF : Boolean;
begin
    EOF := False;
    Assign(f,'Dic.txt');
    Rewrite(f);

    Writeln('When you finish enter <End>');

    While EOF = false do 
        begin
            Readln(x);
            If x = 'End' then EOF := True
            else Write(f,x);
        end;


    Close(f);

End.

I am expecting that 'Type Str20:string[20]; will not give any errors, and can't understand the problem.

Upvotes: 1

Views: 113

Answers (1)

MartynA
MartynA

Reputation: 30715

In type declarations, you use an equals sign rather than a colon, as in:

 Type Str20 = String[20] 

Btw, you don't need to define your own EOF, you could use the built-in EOF function:

while not Eof(x) do ...

That way, you don't need the End in the source file.

Upvotes: 2

Related Questions