From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA04247; Fri, 13 Jun 2003 22:31:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA04870 for ; Fri, 13 Jun 2003 22:31:09 +0200 (MET DST) Received: from jamlikhet.polytechnique.org (b.mx.polytechnique.org [129.104.30.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5DKV8H29523 for ; Fri, 13 Jun 2003 22:31:08 +0200 (MET DST) Received: from alan-schm1p.inria.fr (DHCP12-10.CIS.UPENN.EDU [158.130.13.30]) by ssl.polytechnique.org (Postfix) with ESMTP id 65B80C229 for ; Fri, 13 Jun 2003 22:31:03 +0200 (CEST) Received: by alan-schm1p.inria.fr (Postfix, from userid 501) id F03924202; Fri, 13 Jun 2003 16:28:20 -0400 (EDT) Date: Fri, 13 Jun 2003 16:28:20 -0400 From: Alan Schmitt To: caml-list@inria.fr Subject: [Caml-list] scanf and %2c Message-ID: <20030613202820.GM9367@alan-schm1p> Mail-Followup-To: caml-list@inria.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-Editor: Vim http://vim.sf.net/ X-Info: http://pauillac.inria.fr/~aschmitt/ X-Operating-System: Linux/2.4.21pre4-1mdk (i686) X-Uptime: 16:15:31 up 2 days, 14:57, 2 users, load average: 0.09, 0.08, 0.03 X-Spam: no; 0.00; scanf:01 sscanf:01 val:01 char:01 exception:02 string:03 let:04 parse:04 fun:08 scan:09 something:09 shouldn't:10 chars:12 schmitt:13 hacker:15 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 = 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 = 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