c - different behaviour of scanf function with different format-specifiers -


when use scanf %d or %f, skips white-space characters. on other hand when used %c reads white-space characters.can elaborate on why happens?

with %d or %f code below skips white-space characters automatically

#include<stdio.h> void main(void) { int i; scanf("%d ",&i); } 

if read input this

#include<stdio.h> void main(void) { char ch; scanf(" %c ",&ch); scanf(" %c",&ch);  /*or this*/ } 

it skips white-space characters. why scanf showing different behaviours format-specifiers????

basically, it's because white space character not valid %d or %f, skip them.

but white space character valid character, %c try process it.

c99 §7.19.6.2 the fscanf function section 8

input white-space characters (as specified isspace function) skipped, unless specification includes [,c,or n specifier.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -