Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

scanf formatted input %nand %p specifiers

Status
Not open for further replies.

sathish.b

Newbie level 1
Joined
Oct 23, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,286
conversion specification

what's the use of %n & %p in scanf...
plz tellme anybody know about this
please explain with example...with output also....

thank u for replying in advance[/b]
 

sshahid47

Advanced Member level 4
Joined
Nov 5, 2004
Messages
101
Helped
15
Reputation
30
Reaction score
2
Trophy points
1,298
Activity points
974
Hi,

you use %n in scanf for getting the integer equal to the number of characters read so far

eg:

int n = 0;
char str[100]={0};
scanf("%s %n",&str,&n);

if you now input the following to this program

abc<enter>
a<enter>

then

str = "abc"
and n=4, indicating that till now 4 characters has been entered i,e a b c and a.


you use %p to read the pointer value from the input

eg:

int *c=0;
scanf("%p",&c);

if you input the following to this program

1) abc, then the value of c will be 0x00000abc ,

2) absss, then the value of c will be 0x000000ab, note that it ignored sss coz they are not valid hex codes.

hope that clears up for you.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top