concat problem

I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
This may be 2 or 3 or 4.THANK YOU!!!

program test;
var
k : string;

function add(st : array of string) : string;
var
i : integer;
begin
for i := 1 to high(st) do
end;

begin
writeln(k);
end.

• : I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: This may be 2 or 3 or 4.THANK YOU!!!
:
: program test;
: var
: k : string;
:
: function add(st : array of string) : string;
: var
: i : integer;
: begin
: for i := 1 to high(st) do
: end;
:
: begin
: writeln(k);
: end.
:
I hope I'm not misunderstanding your problem, but if you are trying to concatenate those two strings, you will have to pass two parameters to your function. You don't need to loop thru the string. Just do:

[code]
begin
end;
[/code]

If you mean that you may want to concatenate 2,3,or 4 strings, you could pass an array of strings and an integer to specify the number of strings in your array that you wish to concatenate.
• Sorry!!I wanted write a program is that:
The following statement should be write
How to write the function??
k assign to string
This program like concat function
But I wanted to write it
k := abc('a','f');
k := abc('fv,'h','sdf');

: : I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: : This may be 2 or 3 or 4.THANK YOU!!!
: :
: : program test;
: : var
: : k : string;
: :
: : function add(st : array of string) : string;
: : var
: : i : integer;
: : begin
: : for i := 1 to high(st) do
: : end;
: :
: : begin
: : writeln(k);
: : end.
: :
: I hope I'm not misunderstanding your problem, but if you are trying to concatenate those two strings, you will have to pass two parameters to your function. You don't need to loop thru the string. Just do:
:
: [code]
: begin
: end;
: [/code]
:
: If you mean that you may want to concatenate 2,3,or 4 strings, you could pass an array of strings and an integer to specify the number of strings in your array that you wish to concatenate.
:

• : Sorry!!I wanted write a program is that:
: The following statement should be write
: How to write the function??
: k assign to string
: This program like concat function
: But I wanted to write it
: k := abc('a','f');
: k := abc('fv,'h','sdf');
:
:
: : : I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: : : This may be 2 or 3 or 4.THANK YOU!!!
: : :
: : : program test;
: : : var
: : : k : string;
: : :
: : : function add(st : array of string) : string;
: : : var
: : : i : integer;
: : : begin
: : : for i := 1 to high(st) do
: : : end;
: : :
: : : begin
: : : k := add('abc','sdgsdg');
: : : writeln(k);
: : : end.
: : :
: : I hope I'm not misunderstanding your problem, but if you are trying to concatenate those two strings, you will have to pass two parameters to your function. You don't need to loop thru the string. Just do:
: :
: : [code]
: : function add(st1 :string; st2:string):string;
: : begin
: : end;
: : [/code]
: :
: : If you mean that you may want to concatenate 2,3,or 4 strings, you could pass an array of strings and an integer to specify the number of strings in your array that you wish to concatenate.
: :
:
:
The only ways you can solve this problem is by using linked lists or a recursive function. The way you want to is impossible in most Pascal versions, because the write and read statements are not compiled as normal statements.
Here is the recursive solution using Perran's function:
[code]
[/code]
• It looks to me like you have the right idea, but I think
your array needs to be zero-based.
for i := 1 to high(st) do
Try this:
for i := 0 to high(st) do
Or maybe:
for i := low(st) to high(st) do

It is usually a good idea to initialize local variables first:

AFAIK, Turbo Pascal does not support strings > 255 chars,
so there is a good chance your result may be truncated if
you feed it too much data.

: I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: This may be 2 or 3 or 4.THANK YOU!!!
:
: program test;
: var
: k : string;
:
: function add(st : array of string) : string;
: var
: i : integer;
: begin
: for i := 1 to high(st) do
: end;
:
: begin
: writeln(k);
: end.
:
• I have try this
but it said

"Free Pascal Compiler version 1.0.6 [2002/04/23] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Target OS: Win32 for i386
Compiling c:pascal_pgmsourceconcat.pas
concat.pas(15,19) Error: Wrong amount of parameters specified
concat.pas(16,7) Fatal: There were 1 errors compiling module, stopping"

It looks to me like you have the right idea, but I think
: your array needs to be zero-based.
: for i := 1 to high(st) do
: Try this:
: for i := 0 to high(st) do
: Or maybe:
: for i := low(st) to high(st) do
:
:
:
: It is usually a good idea to initialize local variables first:
:
:
: AFAIK, Turbo Pascal does not support strings > 255 chars,
: so there is a good chance your result may be truncated if
: you feed it too much data.
:
:
:
:
: : I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: : This may be 2 or 3 or 4.THANK YOU!!!
: :
: : program test;
: : var
: : k : string;
: :
: : function add(st : array of string) : string;
: : var
: : i : integer;
: : begin
: : for i := 1 to high(st) do
: : end;
: :
: : begin
: : writeln(k);
: : end.
: :
:

• I've not much experience with FreePascal, but if you are trying to pass a dynamic array to a procedure, you'll need to change the calling code to:
[code]
[/code]
The array-brackets ("[" & "]") are important here to make the parameter an array.

: I have try this
: but it said
:
: "Free Pascal Compiler version 1.0.6 [2002/04/23] for i386
: Copyright (c) 1993-2002 by Florian Klaempfl
: Target OS: Win32 for i386
: Compiling c:pascal_pgmsourceconcat.pas
: concat.pas(15,19) Error: Wrong amount of parameters specified
: concat.pas(16,7) Fatal: There were 1 errors compiling module, stopping"
:
: It looks to me like you have the right idea, but I think
: : your array needs to be zero-based.
: : for i := 1 to high(st) do
: : Try this:
: : for i := 0 to high(st) do
: : Or maybe:
: : for i := low(st) to high(st) do
: :
: :
: :
: : It is usually a good idea to initialize local variables first:
: :
: :
: : AFAIK, Turbo Pascal does not support strings > 255 chars,
: : so there is a good chance your result may be truncated if
: : you feed it too much data.
: :
: :
: :
: :
: : : I have written this program ,but i found some problem that I cannot solve.The point is in the function ,I don't know how many parameter.
: : : This may be 2 or 3 or 4.THANK YOU!!!
: : :
: : : program test;
: : : var
: : : k : string;
: : :
: : : function add(st : array of string) : string;
: : : var
: : : i : integer;
: : : begin
: : : for i := 1 to high(st) do
: : : end;
: : :
: : : begin
: : : k := add('abc','sdgsdg');
: : : writeln(k);
: : : end.
: : :
: :
:
:

• : The array-brackets ("[" & "]") are important here to make the
: parameter an array.

You are right, zibadian - I overlooked that one!

FreePascal does support long strings, but you must compile
with the {\$H+} option.
• Yes I can write this program
but I wanted to write a function is concat
because I interesting in string function
How to write a concat function that do not need ("[" & "])"
: : The array-brackets ("[" & "])" are important here to make the
: : parameter an array.
:
: You are right, zibadian - I overlooked that one!
:
: FreePascal does support long strings, but you must compile
: with the {\$H+} option.
:

• In most Pascals (TP & Delphi I'm sure) you need to rebuild the compiler itself for that (See my post of 2003-5-31 for details).

: Yes I can write this program
: but I wanted to write a function is concat
: because I interesting in string function
: How to write a concat function that do not need ("[" & "])"
: : : The array-brackets ("[" & "])" are important here to make the
: : : parameter an array.
: :
: : You are right, zibadian - I overlooked that one!
: :
: : FreePascal does support long strings, but you must compile
: : with the {\$H+} option.
: :
:
:

• : I have written this program ,but i found some problem that I cannot solve.
: The point is in the function ,I don't know how many parameter.
: This may be 2 or 3 or 4.THANK YOU!!!

If you know that the function always takes 2 or 3 or 4 parameters
( This is what you say )

You can also use overloaded functions:

[code]
begin
end;

begin
add := s1 + s2 + s3;
end;

begin
add := s1 + s2 + s3 + s4;
end;
[/code]
• But I do not know how many parameters
I wanted to write a program like concat
Concat can support many parameters or 2 parameters

: : I have written this program ,but i found some problem that I cannot solve.
: : The point is in the function ,I don't know how many parameter.
: : This may be 2 or 3 or 4.THANK YOU!!!
:
: If you know that the function always takes 2 or 3 or 4 parameters
: ( This is what you say )
:
: You can also use overloaded functions:
:
: [code]
: begin
: add := s1 + s2;
: end;
:
: begin
: add := s1 + s2 + s3;
: end;
:
: begin
: add := s1 + s2 + s3 + s4;
: end;
: [/code]
:

• : But I do not know how many parameters
: I wanted to write a program like concat
: Concat can support many parameters or 2 parameters

Well, then you could write 255 different overloaded functions. :-o

Or you can use '[' and ']', like any other pascal programmer would do.

Or you can read the FreePascal sources and
find out how concat() is implemented...
• Yes ,I wanted to see source of the pascal compiler,
But I have find out most of compiler
I also cannot find the source
Can you give me??

: : But I do not know how many parameters
: : I wanted to write a program like concat
: : Concat can support many parameters or 2 parameters
:
:
: Well, then you could write 255 different overloaded functions. :-o
:
: Or you can use '[' and ']', like any other pascal programmer would do.
:
: Or you can read the FreePascal sources and
: find out how concat() is implemented...
: