🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #647

Re: WHAT COULD BE WRONG?

#647
From: Osmo Ronkanen
Date: Thu, 18 May 2000 00:00
51 lines
2378 bytes
In article <D0OU4.6707$C9.118410@news1.online.no>,  <br-pede@online.no> wrote:
>
>
>Here is the snip of the program that is causing trouble:
>
>procedure lookup;
>begin
>    writeln;
>    write('please enter word to be looked up: ');
>    readln( s ); { s : STRING; }
>    if s = '' then exit; { this doesn't work,
>                           unless running a couple of
>    assign(f,'wordlist.dat'); reset(f);
>    repeat
>         read(f,t); { t : STRING }
>         if t = s then found := true   else found := false; {found : BOOLEAN}
>    until eof(f);

There is no reason whatsoever to set found false in the loop. You, however,
must set it false before the loop. Also once you have found the word
there is no need to continue.

Using read with string is problematic as it does not skip end of lines
but starts to return empty strings. If the items are one word per line
then use readln instead. If there are several entries per line, you
need to do some parsing.

Btw if the proper condition was really be that, then you should write:
found := t=s; That is far more readable.


>    close(f); {f : FILE OF STRING}

Is that really file of string???? That would be truly strange.

Btw where have you defined all the variables like found? Do not use
global variables.

>    if not found then begin
>         writeln('the word ', s, 'is not found in the list');
>         lookup;
>      end;{if}
>    writeln('the word ', s, ' is found in the list');
>end;{ procedure lookup}
>

What you really should do is write as function Find() which returns if
the string is found. It is better to isolate action from IO.


Osmo
Technical Details
Message-ID: <8g0is2$n7c$1@kruuna.Helsinki.FI>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <D0OU4.6707$C9.118410@news1.online.no>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111659,1d4aea8798c741f5
X-Google-Attributes: gid111659,public
X-Google-Thread: 1097b9,1d4aea8798c741f5
X-Google-Attributes: gid1097b9,public
From: ronkanen@cc.helsinki.fi (Osmo Ronkanen)
Subject: Re: WHAT COULD BE WRONG?
Date: 2000/05/18
Message-ID: <8g0is2$n7c$1@kruuna.Helsinki.FI>
X-Deja-AN: 624940717
References: <D0OU4.6707$C9.118410@news1.online.no>
X-Complaints-To: usenet@news.helsinki.fi
X-Trace: oravannahka.helsinki.fi 958648004 3578 128.214.205.14 (18 May 2000 11:06:44 GMT)
Organization: University of Helsinki
NNTP-Posting-Date: 18 May 2000 11:06:44 GMT
Newsgroups: comp.lang.pascal.borland,dk.edb.programmering.pascal