which function is used to clear the buffer stream on gcc?
for example:
I wrote following code on gcc
#include<stdio.h>
int main(void)
{
char ch;
int a,b;
printf("\nenter two numbers:\t");
scanf("%d%d",&a,&b);
printf("enter number is %d and %d",a,b);
printf("\nentercharacter:\t");
scanf("%c",&ch);
printf("enter character is %c",ch);
return 0;
}
in above progarm ch could not be scan.
why?plz tell me solution.
Answers were Sorted based on User's Feedback
Answer / nikhil
after scanning integers if we scan character this happens.
it is a bug of scanf
so to solve this give a space in scanf before %c like this :
scanf(" %c",&ch);
so that it will wait for the character.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / juma ogutu
In the scanf function,in
the format specifier,try
out %s rather than %c
and check out the
output
| Is This Answer Correct ? | 0 Yes | 0 No |
create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00
Design an implement of the inputs functions for event mode
why java is platform independent?
main() { int c=- -2; printf("c=%d",c); }
All the combinations of prime numbers whose sum gives 32
Is the following code legal? struct a { int x; struct a *b; }
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print
what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }
Extend the sutherland-hodgman clipping algorithm to clip three-dimensional planes against a regular paralleiepiped
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }
what is the code of the output of print the 10 fibonacci number series
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }