From: Robert Roessler <roessler@rftp.com>
To: Francois Berenger <berenger@riken.jp>, caml-list@inria.fr
Subject: Re: [Caml-list] Scanf.sscanf surprised me
Date: Mon, 07 Oct 2013 20:28:41 -0700 [thread overview]
Message-ID: <52537BE9.6080005@rftp.com> (raw)
In-Reply-To: <525374ED.2010906@riken.jp>
Francois Berenger wrote:
> This example line and scanning format work:
>
> # let line = "active_ZINC01535869
> 0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0.379";;
> val line : string =
> "active_ZINC01535869
> 0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0.379"
> # Scanf.sscanf line "%s %f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f" (fun name s1
> s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7,
> s8, s9, s10, s11));;
> - : string * float * float * float * float * float * float * float *
> float * float * float * float
> =
> ("active_ZINC01535869", 0.47, 0.389, 0.479, 0.453, 0.47, 0.631, 0.562,
> 0.59, 0.677, 0.558, 0.379)
>
> This one doesn't:
>
> # let line =
> "active_ZINC01535869,0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0.379";;
> val line :
> string =
>
> "active_ZINC01535869,0.470,0.389,0.479,0.453,0.470,0.631,0.562,0.590,0.677,0.558,0.379"
>
> # Scanf.sscanf line "%s,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f" (fun name s1
> s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 -> (name, s1, s2, s3, s4, s5, s6, s7,
> s8, s9, s10, s11));;
> Exception: End_of_file.
>
> I am quite surprised.
> I was expecting the first separator being a space or a coma
> to behave the same.
The specification of scanf "%s" is "Any number of non-whitespace
characters, stopping at the first whitespace character found".
So, perhaps not that surprising?
Regards,
--
Robert Roessler
next prev parent reply other threads:[~2013-10-08 3:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-08 2:58 Francois Berenger
2013-10-08 3:28 ` Robert Roessler [this message]
2013-10-08 4:30 ` Gabriel Scherer
2013-10-08 15:23 ` Eric Cooper
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=52537BE9.6080005@rftp.com \
--to=roessler@rftp.com \
--cc=berenger@riken.jp \
--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