caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] scanf and %2c
@ 2003-06-13 20:28 Alan Schmitt
  2003-06-19  8:57 ` Pierre Weis
  2003-06-20  9:06 ` Pierre Weis
  0 siblings, 2 replies; 5+ messages in thread
From: Alan Schmitt @ 2003-06-13 20:28 UTC (permalink / raw)
  To: caml-list

Hi,

As I needed to parse some string representing time (of the form hh:mm), 
I decided to use scanf. The correct code to do it is:
# let time_parse s =
  Scanf.sscanf s "%2s:%2s" (fun a b -> a,b) 
  ;;
val time_parse : string -> string * string = <fun>

but of course this is not what I tried first, thinking that I wanted 
a string of two chars:
# let time_parse s =
      Scanf.sscanf s "%2c:%2c" (fun a b -> a,b) 
      ;;
val time_parse : string -> char * char = <fun>

this leads to the following:

# time_parse "10:20" ;;
Exception: Scanf.Scan_failure "scanf: bad input at char number 2: 0".
# time_parse "1:2" ;;
- : char * char = ('1', '2')

So shouldn't there be a warning (or an error) when using a size field 
with chars ?

Alan

-- 
The hacker: someone who figured things out and made something cool happen.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-06-20 10:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-13 20:28 [Caml-list] scanf and %2c Alan Schmitt
2003-06-19  8:57 ` Pierre Weis
2003-06-19 15:06   ` Nicolas George
2003-06-20  9:06 ` Pierre Weis
2003-06-20 10:45   ` Alan Schmitt

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