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 -- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: 51FF C1F0 1A77 C6C2 4482 4DDC 117A 9773 7F88 1707
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 -- Maurice Lombardi Laboratoire de Spectrometrie Physique, Universite Joseph Fourier de Grenoble, BP87 38402 Saint Martin d'Heres Cedex FRANCE Tel: 33 (0)4 76 51 47 51 Fax: 33 (0)4 76 63 54 95 mailto:Maurice.Lombardi@ujf-grenoble.fr
participants (3)
-
Frank Heckenbach -
Maurice Lombardi -
Russell Whitaker