caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Andrzej M. Ostruszka" <ostruszk@order.if.uj.edu.pl>
To: Caml List <caml-list@inria.fr>
Subject: "fscanf" functionality ...
Date: Fri, 2 Feb 2001 18:51:40 +0100	[thread overview]
Message-ID: <20010202185140.A12053@order.if.uj.edu.pl> (raw)

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)



             reply	other threads:[~2001-02-04 20:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-02 17:51 Andrzej M. Ostruszka [this message]
2001-02-05 15:47 ` FabienFleutot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010202185140.A12053@order.if.uj.edu.pl \
    --to=ostruszk@order.if.uj.edu.pl \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).