Board index » off-topic » Array of string...

Array of string...


2006-12-27 07:06:22 PM
off-topic13
How can i create an array of string ?
I try to write this code but it isn't right:
type parole=string;
type vettore=array of parole;
var v:vettore;
frase:parole;
i:integer;
begin
for i:=1 to 5 do
begin
writeln('Inserisci una frase, digita 0 per terminare: ');
readln(frase);
if (frase<>'0') then
v[i]:=frase;
end;
end.
 
 

Re:Array of string...

Alberto
You need to tell how big an array. (Else you need pointers)
you wrote:
type parole=string;
type vettore=array of parole; no count
correct:
type parole=string;
type vettore=array[5] of parole; max 5 strings in array
Christen
 

Re:Array of string...

On 2006-12-27, Christen Fihl < XXXX@XXXXX.COM >wrote:
Quote

correct:
type parole=string;
type vettore=array[5] of parole; max 5 strings in array

That won't compile either; I'd change it to
type
vettor = array[1..5] of parole; { 5 strings in the array}
 

{smallsort}

Re:Array of string...

Sure, my mistake.
Normally when programming, I let the fingers do the typing.
When answering mails outside of Turbo/Delphi, I let the brain with all
its faults do the work ;-)
Christen
 

Re:Array of string...

On Wed, 27 Dec 2006 11:06:22 GMT, "Alberto" < XXXX@XXXXX.COM >
wrote:
Quote
How can i create an array of string ?
I try to write this code but it isn't right:

type parole=string;
type vettore=array of parole;

var v:vettore;
frase:parole;
i:integer;
begin
for i:=1 to 5 do
begin
writeln('Inserisci una frase, digita 0 per terminare: ');
readln(frase);
if (frase<>'0') then
v[i]:=frase;
end;


end.
You have to set the length of a dynamic array before you do anything
with it. They are always created at length zero.
Note, also, that this only works in Delphi, not Turbo Pascal.