scanf()

Discussion in 'C Programming' started by BartC, Feb 3, 2012.

  1. BartC

    BartC Guest

    With the scanf() functions, is there any way of finding out how far it's got
    scanning the input?

    For example:

    double x;
    char *s="12.87 91.33";

    sscanf(s,"%lf",&x);

    This reads 12.87 into x; but how can I tell it's consumed 5 characters of
    the input string?

    --
    Bartc
     
    BartC, Feb 3, 2012
    #1
    1. Advertising

  2. "BartC" <> writes:

    > With the scanf() functions, is there any way of finding out how far
    > it's got scanning the input?
    >
    > For example:
    >
    > double x;
    > char *s="12.87 91.33";
    >
    > sscanf(s,"%lf",&x);
    >
    > This reads 12.87 into x; but how can I tell it's consumed 5 characters
    > of the input string?


    %n

    --
    Ben.
     
    Ben Bacarisse, Feb 3, 2012
    #2
    1. Advertising

  3. BartC

    BartC Guest

    "Ben Bacarisse" <> wrote in message
    news:...
    > "BartC" <> writes:


    >> double x;
    >> char *s="12.87 91.33";
    >>
    >> sscanf(s,"%lf",&x);
    >>
    >> This reads 12.87 into x; but how can I tell it's consumed 5 characters
    >> of the input string?

    >
    > %n


    Thanks.

    --
    Bartc
     
    BartC, Feb 3, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Snubis

    Re: safe scanf( ) or gets

    Snubis, Jan 2, 2004, in forum: C++
    Replies:
    0
    Views:
    399
    Snubis
    Jan 2, 2004
  2. JustSomeGuy

    string.scanf?

    JustSomeGuy, Jun 4, 2004, in forum: C++
    Replies:
    5
    Views:
    8,187
    Jorge Rivera
    Jun 6, 2004
  3. Replies:
    5
    Views:
    3,075
    Richard Herring
    Aug 4, 2004
  4. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    3,453
    those who know me have no need of my name
    Apr 3, 2006
  5. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    691
    Richard Bos
    May 2, 2006
Loading...

Share This Page