caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: caml-list@inria.fr
Subject: [Caml-list] scanf and %2c
Date: Fri, 13 Jun 2003 16:28:20 -0400	[thread overview]
Message-ID: <20030613202820.GM9367@alan-schm1p> (raw)

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


             reply	other threads:[~2003-06-13 20:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-13 20:28 Alan Schmitt [this message]
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

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=20030613202820.GM9367@alan-schm1p \
    --to=alan.schmitt@polytechnique.org \
    --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).