From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA11724 for caml-red; Sun, 4 Feb 2001 21:07:21 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA22199 for ; Fri, 2 Feb 2001 18:51:42 +0100 (MET) Received: from order.if.uj.edu.pl (order.if.uj.edu.pl [149.156.90.15]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f12HpfL26596 for ; Fri, 2 Feb 2001 18:51:41 +0100 (MET) Received: (from ostruszk@localhost) by order.if.uj.edu.pl (8.9.3/8.9.3) id SAA12078 for caml-list@inria.fr; Fri, 2 Feb 2001 18:51:40 +0100 Date: Fri, 2 Feb 2001 18:51:40 +0100 From: "Andrzej M. Ostruszka" To: Caml List Subject: "fscanf" functionality ... Message-ID: <20010202185140.A12053@order.if.uj.edu.pl> Mail-Followup-To: Caml List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i Sender: weis@pauillac.inria.fr Hi, Since nowadays OCaml newbies are springing up like mushrooms after rain here's another one :)). Currently I'm converting some program into OCaml in which I've got to read fixed length fields. In C I can use [f]scanf and I'm looking for some nice equivalent - it doesn't need to be exactly the same functionality. For now I'm seek_in'g to a specified position, really_input'ing to the buf'fer and then: for j = 0 to var_len - 1 do let start = ref (j*field_len) and len = ref field_len in while buf.[!start] = ' ' do incr start; decr len; done; v.(j) <- int_of_string (String.sub buf !start !len) done; (I've already learned that int_of_str " 1" will raise an exception :)) I'm sure there is better method - could someone guide me? Best regards PS. There is one big benefit of this conversion -- I've found errors in input data file which I've missed when using fscanf (ints of the form ' 0,5' :)) PPS. I'm sorry but I can't speak French and my English is far from being satisfactory but I hope you'll bear with me :)). -- ____ _ ___ / | \_/ |/ _ \ Andrzej Marek Ostruszka / _ | | (_) | Instytut Fizyki, Uniwersytet Jagiellonski (Cracow) /_/ L|_|V|_|\___/ (PGP <-- finger ostruszk@order.if.uj.edu.pl)