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 |
Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30
union u { union u { int i; int j; }a[10]; int b[10]; }u; main() { printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a)); // printf("%d", sizeof(u.a[4].i)); } a. 4, 4, 4 b. 40, 4, 4 c. 1, 100, 1 d. 40 400 4
main() { extern int i; i=20; printf("%d",sizeof(i)); }
Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };
why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?
int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().
main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
void main() { int c; c=printf("Hello world"); printf("\n%d",c); }
Write a program to check whether the number is prime and also check if it there i n fibonacci series, then return true otherwise return false
what is oop?
main() { int i=10; i=!i>14; Printf ("i=%d",i); }