yjc01@doc.ic.ac.uk wrote:
> The code I came up with is as follows:
I forgot to add, there is no reason to use a reference for buff:
>
> open Unix;;
>
> let file_reader = openfile "sudent.cd" [O_RDONLY] 0o640;;
> let buff = ref "empty";;
let buff = "empty";;
>
> let main () =
> let file_content = read file_reader !buff 1 5 in
let file_content = read file_reader buff 0 5 in
> print_int file_content;
> print_string !buff;;
print_string buff;;
> main ();
This is because you are actually writing directly on the string, so
there is no need for indirection.