by hiker · 5y ago · 0 comments
int getint(const char **s) {
int res = 0;
for (; **s && isspace(**s); (*s)++);
for (; **s && isdigit(**s); (*s)++)
res = 10 * res + **s - '0';
return res;
} function getnum(var s : string):integer;
var
c : char;
value : integer;
begin
value := 0;
while (length(s) <> 0) and NOT(s[1] in ['0'..'9']) do
delete(s,1,1);
while (length(s) <> 0) and (s[1] in ['0'..'9']) do
begin
value := value * 10 + (ord(s[1])-ord('0'));
delete(s,1,1);
end;
getnum := value;
end;But it is unsafe. Someone might mistype * * s as *s and then bad things happen.
Pascal strings are basically memory safe. With range checking enabled, you can write whatever and it can only access characters in the string.
Ofc, then people disable the range checking in release builds to make it faster