caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Robert Roessler <roessler@rftp.com>
Cc: Francois Berenger <berenger@riken.jp>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Scanf.sscanf surprised me
Date: Tue, 8 Oct 2013 06:30:00 +0200	[thread overview]
Message-ID: <CAPFanBG6ieJ7+37oV6ud-ZprNRqpsFoBCJRUvOL+i_9tRuCUPA@mail.gmail.com> (raw)
In-Reply-To: <52537BE9.6080005@rftp.com>

[-- Attachment #1: Type: text/plain, Size: 2153 bytes --]

Use "%s@,%f..." to specify (with @) that the string should stop at the
first comma.


On Tue, Oct 8, 2013 at 5:28 AM, Robert Roessler <roessler@rftp.com> wrote:

> 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
>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/**arc/caml-list<https://sympa.inria.fr/sympa/arc/caml-list>
> Beginner's list: http://groups.yahoo.com/group/**ocaml_beginners<http://groups.yahoo.com/group/ocaml_beginners>
> Bug reports: http://caml.inria.fr/bin/caml-**bugs<http://caml.inria.fr/bin/caml-bugs>
>

[-- Attachment #2: Type: text/html, Size: 3048 bytes --]

  reply	other threads:[~2013-10-08  4:30 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
2013-10-08  4:30   ` Gabriel Scherer [this message]
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=CAPFanBG6ieJ7+37oV6ud-ZprNRqpsFoBCJRUvOL+i_9tRuCUPA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=berenger@riken.jp \
    --cc=caml-list@inria.fr \
    --cc=roessler@rftp.com \
    /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).