I am trying to read a file and return the element read from the file as input to another function.
How can I return a value when I read from a file? I tried everything I know and still hopelessly lost.
My code is as follows:
let file = "code.txt";; let oc = open_out file in (* create or truncate file, return channel *) fprintf oc "%s\n" (play); (* write code to file returned from calling (play) function *) close_out oc ;; (*read from file*) let read l= let fx = let ic = open_in file in let line = input_line ic in (* read line from in_channel and discard \n *) print_endline line; (* write the result to stdout *) ((x ^ line) :: l); flush stdout; close_in ic ; in fl ;; prompt: read;; function call outputs: - : unit = ()
My file contains a line, which is the code needed to enter another function.
Please, help. I am not sure where I am going wrong.
Thanks.
source share