Because Pascal was originally designed for beginning programmers, the first character in a string type variable has an index of 1, not 0!
The following code counts the number of spaces in a string:
var
inputLine : string [80];
spaceCount : integer;
i : integer;
begin
readln(inputLine);
spaceCount := 0;
i := 1;
while i <= length(inputLine) do
begin
if inputLine[i] = ' ' then
spaceCount := spaceCount + 1
end;
writeln('the input line has ',spaceCount,' space(s)')
end.