Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-12

problem with array of string

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dariusz Mazur

I have problem with two dimension array of string

my program:

procedure testlinie;
var
    linie  : array[0..1,0..100] of shortstring;
    i,ii : integer;
begin
   fillchar(linie,sizeof(linie),0);
   for i := 0 to 1 do begin
     for ii:= 1 to 10 do begin
       linie[i,ii]:= linie[i,ii]+char(64+ii);
       writeln(i:5,ii:5,linie[i,ii]) ;
     end;
   end;
end;

during execution output is:
0 1 A
0 2 B
0 3 C etc.

but should be:
0 1 A
0 2 AB
0 3 ABC

on Delphi all works OK.

and second problem is with Watch list: (maybe this part should be on Lazarus list)
I've added Watch at cursor : linie[0,1]
and i see:
for linie[0,1] = {'' <repeats 100 times>} < 1. I want only one string
< 2. even that after 5 iteration
should be <'A','B','C'>
< 3 and after 15 iteration, for i=1
Watch List is showing line[0,1]= {'A','B','C','D .., for me line [1] is showing not line [0]

I use current (-2 days) FPC

Darek

PS.I know my poor English, but maybe someone understand this.

Reply by email

Marco van de Voort
to Dariusz Mazur
Show quoted text 23 lines
I have problem with two dimension array of string my program: procedure testlinie; var linie : array[0..1,0..100] of shortstring; i,ii : integer; begin fillchar(linie,sizeof(linie),0); for i := 0 to 1 do begin for ii:= 1 to 10 do begin linie[i,ii]:= linie[i,ii]+char(64+ii); writeln(i:5,ii:5,linie[i,ii]) ; end; end; end; during execution output is: 0 1 A 0 2 B 0 3 C etc.

This seems the correct output to me. Note that the inner loop never runs twice for the same values of i and ii, so longer strings can't be formed.

Show quoted text 6 lines
but should be: 0 1 A 0 2 AB 0 3 ABC on Delphi all works OK.

Are you sure? With 100% the same source?

Reply by email

Unknown author
to Dariusz Mazur: I have problem with two dimension array of string my program: procedure testlinie; var…
Dariusz Mazur wrote 30 lines
I have problem with two dimension array of string my program: procedure testlinie; var linie : array[0..1,0..100] of shortstring; i,ii : integer; begin fillchar(linie,sizeof(linie),0); for i := 0 to 1 do begin for ii:= 1 to 10 do begin linie[i,ii]:= linie[i,ii]+char(64+ii); writeln(i:5,ii:5,linie[i,ii]) ; end; end; end; during execution output is: 0 1 A 0 2 B 0 3 C etc. but should be: 0 1 A 0 2 AB 0 3 ABC on Delphi all works OK.

I seriously doubt this:

home: >dcc testlinie.pp
Borland Delphi for Linux Version 14.5
Copyright (c) 1983,2002 Borland Software Corporation testlinie.pp(22)
23 lines, 0.00 seconds, 23032 bytes code, 3088 bytes data. home: >./testlinie
0 1A
0 2B
0 3C
0 4D
0 5E
0 6F
0 7G
0 8H
0 9I
0 10J
1 1A
1 2B
1 3C
1 4D
1 5E
1 6F

The FPC output is exactly the same.

Michael.

Reply by email

Adam Naumowicz
to Unknown author
Show quoted text 34 lines
On Mon, 20 Dec 2004, Dariusz Mazur wrote: > I have problem with two dimension array of string > > my program: > > procedure testlinie; > var > linie : array[0..1,0..100] of shortstring; > i,ii : integer; > begin > fillchar(linie,sizeof(linie),0); > for i := 0 to 1 do begin > for ii:= 1 to 10 do begin > linie[i,ii]:= linie[i,ii]+char(64+ii); > writeln(i:5,ii:5,linie[i,ii]) ; > > end; > end; > end; > > during execution output is: > 0 1 A > 0 2 B > 0 3 C etc. > > but should be: > 0 1 A > 0 2 AB > 0 3 ABC > > on Delphi all works OK. I seriously doubt this:

Me either, but it seems that there is a simple typo in the inner loop (ii instead of ii-1), so it should go like that:

      for ii:= 1 to 10 do begin
       linie[i,ii]:= linie[i,ii-1]+char(64+ii);
        writeln(i:5,ii:5,linie[i,ii]) ;
      end;

Best,

Adam

Reply by email

Dariusz Mazur
to Marco van de Voort: This seems the correct output to me. Note that the inner loop never runs twice for the…

Sorry,
I make but when i prepare test program
with FPC all work OK, bug is in WatchList
I send second post to Lazarus list.

Darek

Marco van de Voort wrote 50 lines
>I have problem with two dimension array of string > >my program: > >procedure testlinie; >var > linie : array[0..1,0..100] of shortstring; > i,ii : integer; >begin > fillchar(linie,sizeof(linie),0); > for i := 0 to 1 do begin > for ii:= 1 to 10 do begin > linie[i,ii]:= linie[i,ii]+char(64+ii); > writeln(i:5,ii:5,linie[i,ii]) ; > > end; > end; >end; > >during execution output is: >0 1 A >0 2 B >0 3 C etc. > > This seems the correct output to me. Note that the inner loop never runs twice for the same values of i and ii, so longer strings can't be formed. >but should be: >0 1 A >0 2 AB >0 3 ABC > >on Delphi all works OK. > > Are you sure? With 100% the same source? _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Eduardo Morras
to Dariusz Mazur: I have problem with two dimension array of string my program: procedure testlinie; var…
you wrote 30 lines
I have problem with two dimension array of string my program: procedure testlinie; var linie : array[0..1,0..100] of shortstring; i,ii : integer; begin fillchar(linie,sizeof(linie),0); for i := 0 to 1 do begin for ii:= 1 to 10 do begin linie[i,ii]:= linie[i,ii]+char(64+ii); writeln(i:5,ii:5,linie[i,ii]) ; end; end; end; during execution output is: 0 1 A 0 2 B 0 3 C etc. but should be: 0 1 A 0 2 AB 0 3 ABC on Delphi all works OK.

On delphi it works exactly the same. Your code never do what you want, only what it can do. The problem is that you have a matrix (2,101) with strings. If you do

linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=0) ->   linie[0,0]:=
linie[0,0]+'A'
linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=1) ->   linie[0,1]:=
linie[0,1]+'B'
linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=2) ->   linie[0,2]:=
linie[0,2]+'C'

so on each inner cycle you are adding a letter to other string in the matrix. The linie structure is in fact a tridimensional matrix [0..1,0..100,0..sizeof(shortstring)] of char . It's not a bug in the compiler, only in your code.

HTH

------------------------------------------------------------------------------------------------------------------------------------------------------------------- Scientists have shown that the moon is moving away at a tiny yet measurable distance from the earth every year.
If you do the math, you can calculate that 85 million years ago the moon was orbiting the earth at a distance of
about 35 feet from the earth's surface. This would explain the death of the dinosaurs. The tallest ones, anyway.

Reply by email