Re: ------> GNU Pascal <-----
On Thu, Oct 28, 1999 at 08:03:08PM -0300, Phillip Neumann was heard to say:
> Hi,
>
> well, i figure out this little program that works for turbo pascal but doesnt for gnu pascal. It does what i want, and i guess there is no functions in pascal that will do this... my first problem is that i have to do it in this lang. my second prob!
> lem is that i cannot work at home, couse gnu pascal wont accept "the line". it gives me "array index out of range" at compilatoin time. without that line, i cannot (dont know how to...) set the length of b (so its 0 by default i guess), for example if!
> something=print, print(b) wont print anything, couse b will have length 0. Someboady remember how to set the length of a string? (via a funcion or manually, as ive try here...)
>
>
>
> a:='Hola soy yo bla AS as';
> n:=1;
> while n<=length(a) do
> begin
> m:=1;
> while (a[n]<>chr(32)) and (n<=length(a)) do
> begin
> b[m]:=a[n];
> n:=n+1;
> m:=m+1;
> end;
> b[0]:=chr(m-1); <------ the line
> something(b); <------ "something"
> n:=n+1;
>
> end;
What's wrong with b:=b+a[n]? I'm also *certain* that there are Pascal
functions available to get a substring of a string and to search for the first
occurance of a character in a string. You can use those to do this in a much
nicer way.
Oh, and I believe that you can compare a[n] to a character constant:
while (a[n]<>' ') and (n<=length(a)) do
.
.
(but it's been a while since I did Pascal programming)
Also, your indentation is making it difficult to read. Try the following
instead:
a:='Hola soy yo bla AS as';
n:=1;
while n<=length(a) do
begin
while (a[n]<>' ') and (n<=length(a)) do
begin
b:=b+a[n];
n:=n+1;
end;
something(b);
end;
--
Radicalism:
The conservatism of tomorrow injected into the affairs of today.
-- Ambrose Bierce (1842-1914)
Reply to: