wondering all about C, can you demystify this
I am using turbo C
I have this code
scanf(“%d , %d”,&a,&b);
printf(“%d,%d”,a,b);
scanf(”%c”,&c);
printf(“%d,%d”,a,b);
then scanf for doesnt scan value of c
output is : 1,2
if I use this
scanf(“%d , %d”,&a,&b);
printf(“%d,%d”,a,b);
scanf(”%c ”,&c);//note a blank after %c
printf(“%d,%d”,a,b);
then it scan value of c.
output is 1,2 1,2
same code
scanf(“%d , %d”,&a,&b);
printf(“%d,%d”,a,b);
scanf(”%1s”,&c);
printf(“%d,%d”,a,b);
in this segment value of a will be displayed but value of b will be set 0
output is 1,2 1,0
can you explain the answers of both the questions.
didnt got the answers yet help me…….
How do you know that no character is being scanned for
cin the first case? I assume it is because you provide a unexhibited print statement and don’t see anything.Read the man page careful about the behavior of the %c specifier:
[emphasis added]
If you input has a form like
1, 2 athe first scan eats the1 , 2and leaves thea, at which point the second scan eats the space. Not sure how the second example would work in this case.Anon. is on the money about the third case.