473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

scanf

Ab
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.

Nov 15 '05 #1
6 3011
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."

Nov 15 '05 #2
"Ab" <ab***************@honeywell.com> wrote:
What does the "%%" format specifier in scanf do?


It stops trolls from reading the fscking manual.

HTH; HAND; FOAD.

Richard
Nov 15 '05 #3
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.
Nov 15 '05 #4
"Emmanuel Delahaye" <em***@YOURBRAnoos.fr> 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) ks***@mib.org <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.
Nov 15 '05 #5
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

Nov 15 '05 #6
"Ab" <ab***************@honeywell.com> 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.
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: B Thomas | last post by:
Hi, I was reading O'Reilly's "Practical C programming" book and it warns against the use of scanf, suggesting to avoid using it completely . Instead it recomends to use using fgets and sscanf....
14
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
7
by: hugo27 | last post by:
obrhy8 June 18, 2004 Most compilers define EOF as -1. I'm just putting my toes in the water with a student's model named Miracle C. The ..h documentation of this compiler does state that when...
4
by: sushant | last post by:
hi why do we use '&' operator in scanf like scanf("%d", &x); but why not in printf() like printf("%d" , x); thnx in advance sushant
17
by: Lefty Bigfoot | last post by:
Hello, I am aware that a lot of people are wary of using scanf, because doing it improperly can be dangerous. I have tried to find a good tutorial on all the ins and outs of scanf() but been...
33
by: Lalatendu Das | last post by:
Dear friends, I am getting a problem in the code while interacting with a nested Do-while loop It is skipping a scanf () function which it should not. I have written the whole code below. Please...
14
by: main() | last post by:
I know this is the problem that most newbies get into. #include<stdio.h> int main(void) { char a; scanf("%c",&a); /*1st scanf */ printf("%c\n",a); scanf("%c",&a); /*2nd scanf*/...
8
by: Neil | last post by:
Hello Just to let you know this not homework, I'm learning the language of C on my own time.. I recently tried to create a escape for user saying printf ("Do you want to continue? (y or n)");...
3
by: Tinku | last post by:
#include<stdio.h> main() { char line; scanf("%", line); printf("%s", line); } it will read and print the line but what is "%" in general we gives %s, %c .
2
by: subramanian100in | last post by:
Consider the following program named as x.c #include <stdlib.h> #include <stdio.h> int main(void) { unsigned int u; char str;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.