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 |
String reverse with time complexity of n/2 with out using temporary variable.
main() { char c=' ',x,convert(z); getc(c); if((c>='a') && (c<='z')) x=convert(c); printf("%c",x); } convert(z) { return z-32; }
main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }
#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?
void main() { int i=5; printf("%d",i++ + ++i); }
void main() { int k=ret(sizeof(float)); printf("\n here value is %d",++k); } int ret(int ret) { ret += 2.5; return(ret); }
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }
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
prog. to produce 1 2 3 4 5 6 7 8 9 10
Write a routine to implement the polymarker function
How we print the table of 3 using for loop in c programing?
write a program in c to merge two array