M
M
mikkeyPG2018-11-05 11:19:47
Pascal
mikkeyPG, 2018-11-05 11:19:47

What does this line do in pascal?

What does the second for do, why is ord here and why subtract 48?
procedure StrToMass(var a:mass; var s:string);
var i:integer;
begin
for i:=1 to 9 do
a[i]:=0;
for i:=1 to length(s) do
inc(a[ord(s[i])-48]);
end;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-11-05
@xpert13

The second for makes a pass through the characters of the string and, as far as I understand, counts the number of characters from 0 to 9. Ord is needed in order to convert the character into a numeric value according to the ascii table, and 48 is taken away, because the numbers in this table start just from 48.

ASCII Table
ASCII-Table.svg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question