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 |
main() { int i=10,j=20; j = i, j?(i,j)?i:j:j; printf("%d %d",i,j); }
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }
Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list)
3 Answers Disney, Google, ZS Associates,
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
18 Answers HCL, IBM, Infosys, LG Soft, Satyam,
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
write a program to Insert in a sorted list
write a program for area of circumference of shapes
main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }
char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']
main() { char * strA; char * strB = I am OK; memcpy( strA, strB, 6); } a. Runtime error. b. I am OK c. Compile error d. I am O
Program to find the largest sum of contiguous integers in the array. O(n)