scanf

Discussion in 'C Programming' started by Ab, Aug 19, 2005.

  1. Ab

    Ab Guest

    What does the "%%" format specifier in scanf do? eg if we write

    char ch;
    scanf("%%", &ch);

    what change if any does it make to ch. If it does not whats the use.
     
    Ab, Aug 19, 2005
    #1
    1. Advertising

  2. Ab wrote:
    > What does the "%%" format specifier in scanf do?


    expects a % character

    > eg if we write
    >
    > char ch;
    > scanf("%%", &ch);
    >
    > what change if any does it make to ch.


    none

    > If it does not whats the use.


    see above


    --
    Nick Keighley

    "The Real Programmer wants a "you asked for it, you got it"
    text editor--complicated, cryptic, powerful, unforgiving,
    dangerous. TECO, to be precise."
     
    Nick Keighley, Aug 19, 2005
    #2
    1. Advertising

  3. Ab

    Richard Bos Guest

    "Ab" <> wrote:

    > What does the "%%" format specifier in scanf do?


    It stops trolls from reading the fscking manual.

    HTH; HAND; FOAD.

    Richard
     
    Richard Bos, Aug 19, 2005
    #3
  4. Ab wrote on 19/08/05 :
    > What does the "%%" format specifier in scanf do? eg if we write


    It's the 'escape' value for '%' in a format string.

    > char ch;
    > scanf("%%", &ch);
    >
    > what change if any does it make to ch. If it does not whats the use.


    Undefined Behaviour (The number of parameters doesn't match the number
    of formaters). Anything could happen.

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    "Mal nommer les choses c'est ajouter du malheur au
    monde." -- Albert Camus.
     
    Emmanuel Delahaye, Aug 19, 2005
    #4
  5. "Emmanuel Delahaye" <> writes:
    > Ab wrote on 19/08/05 :
    >> What does the "%%" format specifier in scanf do? eg if we write

    >
    > It's the 'escape' value for '%' in a format string.
    >
    >> char ch;
    >> scanf("%%", &ch);
    >>
    >> what change if any does it make to ch. If it does not whats the use.

    >
    > Undefined Behaviour (The number of parameters doesn't match the number
    > of formaters). Anything could happen.


    Extra arguments to scanf() are evaluated but are otherwise ignored.
    C99 7.19.6.2p2.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, Aug 19, 2005
    #5
  6. Emmanuel Delahaye wrote:
    > Ab wrote on 19/08/05 :
    > > What does the "%%" format specifier in scanf do? eg if we write

    >
    > It's the 'escape' value for '%' in a format string.
    >
    > > char ch;
    > > scanf("%%", &ch);
    > >
    > > what change if any does it make to ch. If it does not whats the use.

    >
    > Undefined Behaviour (The number of parameters doesn't match the number
    > of formaters). Anything could happen.


    If there are insufficient arguments the behavior is undefined, extra
    arguments are ignored without invoking undefined behavior. The same
    goes for the fprintf functions.

    Robert Gamble
     
    Robert Gamble, Aug 19, 2005
    #6
  7. Ab

    Malcolm Guest

    "Ab" <> wrote
    >
    > What does the "%%" format specifier in scanf do? eg if we write
    >
    > char ch;
    > scanf("%%", &ch);
    >
    > what change if any does it make to ch. If it does not whats the use.
    >

    You are reading some economics data, which contains inflation rates. Since
    there are many definitions of inflation, the economist has prepared the data
    by appending letters, so for instance Keynes'es definition is 2.6%k whilst
    Friedman's definition is expressed as 2.6%f.

    If you try to scan this data using scanf(), the %f will be interpreted as a
    format conversion specifier. So you need to escape the % sign to indicate
    that it is a percentage in the text, not a field specifier. To make it
    easier, the %k also has to be escaped.
     
    Malcolm, Aug 20, 2005
    #7
    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:
    397
    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,070
    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,449
    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:
    688
    Richard Bos
    May 2, 2006
Loading...

Share This Page