Hi this program:
program writebug; var b1, b2: string (80); f: Text; begin Assign (f, 'ref.txt'); Reset (f); readln (f, b2); while not eof(f) do begin ReadLn (f, b1); if b1 [ 1 ] = '=' then writeln( b2, ' ':64 - length( b2 ), 'bug') else WriteLn ( b2); b2 := b1; end; writeln ( b1); Close (f); end.
Using either gpc built with gcc-3.3.3 or gcc-3.4.0 and this input file named ref.txt:
The Alphabetical GPC Language Reference
Abs ===
absolute ========
oops.
gives me this output:
The Alphabetical GPC Language Reference
Abs bug === bug
absolute bug ======== bug
oops.
Unless I have egg on my face (again), the word "bug" should not appear on the "===" lines.
Russ
Russell Whitaker wrote:
this program:
program writebug; var b1, b2: string (80); f: Text; begin Assign (f, 'ref.txt'); Reset (f); readln (f, b2); while not eof(f) do begin ReadLn (f, b1); if b1 [ 1 ] = '=' then
If b1 is empty, b1[1] is undefined (or contains the value from a previous input).
Try
(b1 <> '') and (b1[1] = '=')
or
IsPrefix ('=', b1)
the former(!) is faster.
Frank
On Mon, 26 Apr 2004, Frank Heckenbach wrote:
Russell Whitaker wrote:
[..]
ReadLn (f, b1); if b1 [ 1 ] = '=' then
If b1 is empty, b1[1] is undefined (or contains the value from a previous input).
Ah ha! Now I see. If b1 is empty then b1[1] is past the end of the line. Pardon me, I gotta go wipe some egg...
Thanks, Russ
Russell Whitaker a écrit:
Hi this program:
program writebug; var b1, b2: string (80); f: Text; begin Assign (f, 'ref.txt'); Reset (f); readln (f, b2); while not eof(f) do begin ReadLn (f, b1); if b1 [ 1 ] = '=' then writeln( b2, ' ':64 - length( b2 ), 'bug') else WriteLn ( b2); b2 := b1; end; writeln ( b1); Close (f); end.
Using either gpc built with gcc-3.3.3 or gcc-3.4.0
or gcc-3.2.3 ...
when b1 = '', i.e. length(b1) < 1, the test if b1 [1] = '=' then ... checks for the (invisible) contents which remains at this position from previous operations, i.e. the content of b1 beyond its actual length is not reset by reading. You were may be expecting such a reset or an error (trying to access invalid data, this would be logical but would break down many BP style constructs: filling the chars and afterwards setting the length)?
Maurice