[fpc-pascal]opening files from a text list

DONALD PEDDER jims_son at jedi.apana.org.au
Fri Nov 28 03:52:01 CET 2003


On Fri, 28 Nov 2003, Anton Tichawa wrote:

> function scanblack(var s: string): string;
> var
>   i: integer;
> begin
>   i := 1;
>   repeat
>     if i > length(s) then begin
>       break;
>     end;
>     if s[i] = ' ' then begin
>       break;
>     end;
>     inc(i);
>   until false;
>   result := copy(s, 1, i - 1);
>   delete(s, 1, i - 1);
> end;

   When I compiled the code, I got "identifier not found result", so I
added "result: string;", but even though it then compiles, the function
returns garbage (not "49ers" in the first instance). The original line
gets read in correctly ("49ers at Giants 16 13"), so the problem is after
that. Should there be a line along the lines of "return result" in the
function? I haven't really used functions much (at least not any that
returned anything anyway).

   This code helps me to understand a bit more (at least when I get time
to sit down and look at it some more anyhow) - the above is a different
approach to anything I've used before (having not used strings before), so
I wouldn't have thought of it myself.


>   if scanblack(line) <> 'at' then begin
>     writeln('syntax error');

   I'm getting this coming up, presumably because the functions aren't
quite working.

thanks,
  dp.





More information about the fpc-pascal mailing list