[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Andrzej M. Ostruszka <ostruszk@o...> |
| Subject: | "fscanf" functionality ... |
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)