Reputation: 1861
Hello i'v got simple program which is couting characters in given text until line is empty line only with new line
var
znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
napis: String;
maly: String;
dlugosc: Integer;
znak: char;
begin
napis := 'a';
while napis[1] <> '#13#10'do
begin
readln(napis);
maly:=LowerCase(napis);
for dlugosc:=(length(maly)) downto 1 do
begin
znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
end;
for znak:='a' to 'z' do
writeln(znak, ' ', znaki[znak]);
end;
end.
it fails on while condtion and i dont know why. Pleas give me clue
Upvotes: 3
Views: 2258
Reputation: 8086
One char, napis[1]; can't be 2 chars #13 & #10...
So, I'll do this for example:
var
znaki: array['a'..'z'] of integer = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
napis: String;
maly: String;
dlugosc: Integer;
znak: char;
begin
napis := 'a';
while ((Length(napis) > 0)) do
begin
readln(napis);
// napis := StringReplace(napis, #13#10, #10, [rfReplaceAll]); //useless for a console readln
maly:=LowerCase(napis);
for dlugosc:=(length(maly)) downto 1 do
begin
znaki[maly[dlugosc]]:=znaki[maly[dlugosc]]+1;
end;
for znak:='a' to 'z' do
writeln(znak, ' ', znaki[znak]);
end;
end.
Upvotes: 2
Reputation: 3857
#10
is line feed
#13
is carriage return (i.e. move to beginning of line)
You only need to check for #10.
Upvotes: 2