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



which function is used to clear the buffer stream on gcc? for example: I wrote following code on g..

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

which function is used to clear the buffer stream on gcc? for example: I wrote following code on g..

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

Post New Answer

More C Code Interview Questions

void main() { char ch; for(ch=0;ch<=127;ch++) printf(ā€œ%c %d \nā€œ, ch, ch); }

1 Answers  


main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p } a. Runtime error. b. 1.00000 c. Compile error d. 0.00000

3 Answers   HCL,


Program to Delete an element from a doubly linked list.

4 Answers   College School Exams Tests, Infosys,


What is "far" and "near" pointers in "c"...?

3 Answers  


main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }

2 Answers   HP,






#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  


write a program to Insert in a sorted list

4 Answers   Microsoft,


main() { clrscr(); } clrscr();

2 Answers  


void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā€œ%dā€, i); }

2 Answers  


can u give me the c codings for converting a string into the hexa decimal form......

1 Answers  


program to Reverse a linked list

12 Answers   Aricent, Microsoft, Ness Technologies,


how to delete an element in an array

2 Answers   IBM,


Categories