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 |
void main() { char ch; for(ch=0;ch<=127;ch++) printf(ā%c %d \nā, ch, ch); }
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
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"...?
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }
write a program to Insert in a sorted list
main() { clrscr(); } clrscr();
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(ā%dā, i); }
can u give me the c codings for converting a string into the hexa decimal form......
program to Reverse a linked list
12 Answers Aricent, Microsoft, Ness Technologies,
how to delete an element in an array