caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* "fscanf" functionality ...
@ 2001-02-02 17:51 Andrzej M. Ostruszka
  2001-02-05 15:47 ` FabienFleutot
  0 siblings, 1 reply; 2+ messages in thread
From: Andrzej M. Ostruszka @ 2001-02-02 17:51 UTC (permalink / raw)
  To: Caml List

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)



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: "fscanf" functionality ...
  2001-02-02 17:51 "fscanf" functionality Andrzej M. Ostruszka
@ 2001-02-05 15:47 ` FabienFleutot
  0 siblings, 0 replies; 2+ messages in thread
From: FabienFleutot @ 2001-02-05 15:47 UTC (permalink / raw)
  To: Andrzej M. Ostruszka, Caml List

> 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

That's far from being the first time I can read/hear of somebody asking for
a scanf equivalent. Wouldn't it be a great improvment to the Printf library
?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-02-05 17:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-02 17:51 "fscanf" functionality Andrzej M. Ostruszka
2001-02-05 15:47 ` FabienFleutot

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).