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
extract info from file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-01-26 (15:37)
From: Yan Jun Daisy Chen <yjc01@d...>
Subject: extract info from file

I am trying to extract comments in a text file i.e. text between (* and
*).  I declared a globle sting variable, buff to store them, and want to
store all the comments extracted in a list of string. Is the sting
variable size fixed once I initialise it?

The code I came up with is:

open Unix;;

let fileReader = openfile "student.cd" [O_RDONLY] 0o640;;
let buff = ref "file: ";;
let fileSize = (fstat fileReader).st_size;;
(*let fileSize = 50;;*)
let noOfChar = ref 0;;

let extract_comment ()  =
  let openIndex = 0 in
  noOfChar := read fileReader !buff openIndex fileSize;
  (*print_string !buff;	print_newline();
  print_int !noOfChar;	print_newline();;*)

let main () =
  (*let fileContent = read fileReader !buff 0 5 in
  print_int fileContent;*)

main ();;

Is there a simpler way to do this?