procedure ReverseArray(var A : array of string);
var I,J,L : integer;
begin
for I := Low(A) to High(A) do
begin
L := length(A[I]);
for J := L downto 1 do M := M + A[I];
end;
writeln(M);
end;
begin
for I := 1 to 4 do readln(T[I]);
ReverseArray(T);
sleep(40000);
end.
What I'm trying to do here basically is reverse every string in the array but I'm unable to do it , what the code above do is basically repeat the words depends on their length (I write 'bob' in the array , the procedure will give me 'bob' three times because the length is 3) ... not sure why it's not working properly and what I'm missing
A string is an array of char with some extra bells and whistles added.
So an
array of stringis a lot like anarray of array of char.If you want to reverse the string, you'll have to access every char and reverse it.
Some tips:
Mbut declare a local variable instead.AStr:= AStr + ACharin a loop, if you can avoid it. If you know how long the result is going to be use theSetLengthtrick as shown in the code. It's generates much faster code.Sleepyou can use aReadLnto halt a console app. It will continue as soon as you press a key.writelnin your working routine.array of stringin a parameter definition is an open array; a different thing from a dynamic array.T,K, etc are usually used for generic types, you shouldn't use them for normal variables; Use a descriptive name instead.