Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let read_int in_ch =
- let is_valid ch = ch >= '0' && ch <= '9' in
- let ioc ch = (int_of_char ch)-(int_of_char '0') in
- let res = ref 0 in
- let tmp = ref '0' in
- try
- while true do
- tmp := (input_char in_ch);
- if (is_valid !tmp) then
- begin
- res := !res * 10 + (ioc !tmp);
- end
- else
- raise Exit;
- done;
- !res;
- with
- Exit -> !res;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement