Monday, October 17, 2022

[FIXED] How do I parse an int from a string?

Issue

I'm trying to do this:

let medio a b =
    (a + b);;
let () = Printf.printf "%d + %d  = %d\n" Sys.argv.(1) Sys.argv.(2) (medio Sys.argv.(1) Sys.argv.(2))    

Sys.argv.(1) has to be the arg[1] ~ in C

Now I want to use them like parameters for my function medio, but they're strings. How can I parse them into int?


Solution

You could use the 'int_of_string' function described in the documentation.



Answered By - Hugh Rawlinson
Answer Checked By - Clifford M. (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.