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

String reverse with time complexity of n/2 with out using temporary variable.

10 Answers   NetApp, Symantec,


main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }

1 Answers  


main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }

2 Answers   IBM,


#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?

2 Answers  


void main() { int i=5; printf("%d",i++ + ++i); }

3 Answers  






void main() { int k=ret(sizeof(float)); printf("\n here value is %d",++k); } int ret(int ret) { ret += 2.5; return(ret); }

1 Answers  


main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }

2 Answers   Wipro,


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

0 Answers  


prog. to produce 1 2 3 4 5 6 7 8 9 10

4 Answers   TCS,


Write a routine to implement the polymarker function

0 Answers   TCS,


How we print the table of 3 using for loop in c programing?

7 Answers  


write a program in c to merge two array

2 Answers  


Categories