Hello, I'll get straight to the point. I'm making a program which lets you enter a row of characters, finds words in that row (words are characters separated by spaces) and output them in another row in alphabetical order.
Firstly I wrote this:
Program ...;
Uses crt,sysutils;
const MAX = 100;
type chars = array[1..MAX] of char;
strarray = array[1..MAX] of string;
var symb:chars;
astring:strarray;
d,i,j,s,n:integer;
procedure Input;
begin
n:=0;
while not Eoln and (n < MAX)do
begin
n := n + 1;
Read(symb[n]);
end;
readln;
writeln;
end;
Ok, so basically I enter a number of characters and attach them to a character array.The following code should divide the row of characters.
(For example:
>Input<
Have a nice day
>Output<
Have
a
nice
day
procedure words;
begin
i:=1;
while i<n+1 do
begin
if symb[i]<>' '
then Read(astring[i]);
else WriteLn;
WriteLn(str[i]);
inc(i);
end;
end;
I can do the dividing part by replacing
Read(astring[i]);
with
Write(symb[i]);
but I also want to want to attach those divided words to a string array like this:
(1st element)Have
(2nd)a
(3rd)nice
(4th)day
That's because I think of using AnsiCompareText to compare those words in a string array except I have no idea how to compare a string array with the said function:
This is a rough example of the ACT function:
procedure sort (s1,s2:string);
var r:longint;
begin
R:=AnsiCompareText(s1,s2);
If r<0
then
Write(s2,s1)
else
If r>0
then
Write(s1,s2)
else
Write(s1,s2);
end;
Help as well as different suggestions appreciated.
If the above is confusing, then I shall write how the program should behave:
>Input<
Have a nice day
>Output<
a day Have nice