Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > scanf

Reply
Thread Tools

scanf

 
 
Ab
Guest
Posts: n/a
 
      08-19-2005
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.

 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      08-19-2005
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."

 
Reply With Quote
 
 
 
 
Richard Bos
Guest
Posts: n/a
 
      08-19-2005
"Ab" <(E-Mail Removed)> wrote:

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


It stops trolls from reading the fscking manual.

HTH; HAND; FOAD.

Richard
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      08-19-2005
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.


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-19-2005
"Emmanuel Delahaye" <(E-Mail Removed)> 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.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Robert Gamble
Guest
Posts: n/a
 
      08-19-2005
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

 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      08-20-2005
"Ab" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005? =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 18 05-02-2006 10:53 AM
scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc. =?ISO-8859-1?Q?Martin_J=F8rgensen?= C Programming 185 04-03-2006 02:49 PM
scanf and iostreams paidojoao-groups@yahoo.com C++ 5 08-04-2004 02:14 PM
string.scanf? JustSomeGuy C++ 5 06-06-2004 04:16 PM
Re: safe scanf( ) or gets Snubis C++ 0 01-02-2004 01:53 PM



Advertisments