From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 83EFDBC8C for ; Tue, 25 Jan 2005 23:41:34 +0100 (CET) Received: from woodstock.1969.ws (64-215-156-42.eosinc.net [64.215.156.42]) by nez-perce.inria.fr (8.13.0/8.13.0) with SMTP id j0PMfXjW005271 for ; Tue, 25 Jan 2005 23:41:33 +0100 Received: (qmail 7355 invoked from network); 25 Jan 2005 22:21:11 -0000 Received: from karl.1969.ws (HELO ?10.3.2.15?) (10.3.2.15) by woodstock.1969.ws with SMTP; 25 Jan 2005 22:21:11 -0000 Message-ID: <41F6CB7B.7050406@1969.ws> Date: Tue, 25 Jan 2005 14:43:07 -0800 From: Karl Zilles Organization: 1969 Communications, Inc. User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: yjc01@doc.ic.ac.uk Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] open_file References: <1106691570.41f6c5f250fdc@www.doc.ic.ac.uk> In-Reply-To: <1106691570.41f6c5f250fdc@www.doc.ic.ac.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 41F6CB1D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 compilation:01 ocamlc:01 ocamlopt:01 cmxa:01 overkill:01 pervasives:01 ocaml:01 ocaml:01 beginners:01 unix:01 unix:01 compile:01 strings:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.0 X-Spam-Level: (forgot to copy the list, originally) yjc01@doc.ic.ac.uk wrote: > 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. My guess is that you aren't including the unix library on your compile command line: ocamlc [other_options] unix.cma [other_files] ocamlopt [other_options] unix.cmxa [other_files] > > 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 Strings are indexed from 0, so change above to let file_content = read file_reader !buff 0 5 in > print_int file_content; > print_string !buff;; > main (); > I couldn't work out what went wrong. Can anyone help?!! Also, using the Unix libray is probably overkill for this kind of thing. You might want to switch to the Pervasives library, which is automatically included with all ocaml programs. There is a whole group for asking beginning OCaml questions: http://groups.yahoo.com/group/ocaml_beginners/