(*RICM LP2 2006/2007, fichier fourni avec le tp4*) (*Laure Gonnord et Mathias Peron*) (*exemple de lecture dans un fichier*) (*compiler avec : ocamlc lecture_fichier.ml -o lecture*) (*ensuite, ./lecture nom_du_fichier *) open Format (*pour printf*) open Sys (*pour les entrees/sorties*) (*regarder aussi la doc de la lib standard*) (*http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html*) exception WrongNb let main chan_fich = ( (*do something here with the channel of the file*) ) let _ = try ( let nb_of_args = Array.length (Sys.argv) in if nb_of_args <> 2 then raise WrongNb else let name = Sys.argv.(1) in let chan = open_out name in printf "%s is now open \n" name; main chan; close_out chan; printf "%s has closed successfully \n" name; ) with | Sys_error(s) -> prerr_string ("Sys_error "^s);prerr_newline() | WrongNb -> prerr_string ("File not found") ;prerr_newline()