473,480 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3016
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
9817
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
2703
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
7636
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
17136
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
3468
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
3065
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
13740
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
2356
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
9808
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
6531
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
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6739
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
6929
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
5337
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,...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.