English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-25 (22:19)
From: yjc01@d...
Subject: open_file
I tried to read in a text file and extract the string between (* and *) into a 
variable, buff, by using the openfile and read functions in Unix module. But 
get an error on compilation.

The code I came up with is as follows: 

open Unix;;

let file_reader = openfile "sudent.cd" [O_RDONLY] 0o640;;
let buff = ref "empty";;

let main () =
  let file_content = read file_reader !buff 1 5 in
  print_int file_content;
  print_string !buff;;
main ();
I couldn't work out what went wrong. Can anyone help?!!