[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: GNU Pascal..............



On Thu, Oct 28, 1999 at 01:12:50PM -0300, Phillip Neumann wrote:
> Hello, im having a little problem here with pascal.
> 
> 
> i want to emulate somethig like in bash would be: 
> for b in a do; echo $b  , where a,b are strings.
> 
> a:='Hola soy Phillip';
> n:=1;
> while n<=length(a) do
> begin
> b:=' ';
> 	while a[n]<>chr(32) do
> 	begin
> 	b[n]:=a[n];
> 	n:=n+1;
> 	end;
> writeln(b);
> end;

It's been a looooong time since I use Pascal, but anyway. The problem with the
code above is that you are using the string b way behind it's set length. If
you set b:=' ', then length(b) should give 1, and then you set b inside the
inner loop far behind length(b).

I don't remember the string functions from Pascal, but try to use something
like the strcpy function (copies a string to another) from C. That should work.
Read the docs from gpc-doc. It should gives you something.

> that would print me all the words that are in the a string, right?  Well im not getting anything. writeln(b) wont work. if i do for i:=1 to 255; write(b[i])  it would work, but thats not the idea. Also if i check the length of b, i get length(b)=0, so thats a reason why writeln(b) wont print anything... someboady told me that string[0] has the length of the string, so i have try to set if manually, but every time i write b[0] i get a compilatoin error: "array index out of range"... the person who told me was using turbo pascal for dos...  

Well, yeah, this is true in the DOS world, don't know about gpc though.

-- 
Pedro Guerreiro                     (digito@bigfoot.com)
-------------------------------------------------------- 
Diplomacy: the art of letting someone have your own way.


Reply to: