0

I couldn't display char value in my C code. What's the problem in my coding. Can anyone explain ???

#include <stdio.h> int main(void){  int a;  float b;  double c;  char d;    printf("Enter int \n ");  scanf("%d",&a);    printf("Enter float \n ");  scanf("%f",&b);    printf("Enter double \n");  scanf("%lf",&c);    printf("Enter \n");  scanf("%c",&d);    printf("\nint is %d\n",a);  printf("float is %f\n",b);  printf("double is %lf\n",c);  printf("\nvalue is %c",d);    return 0; }

29th Nov 2020, 7:43 AM
Krishanthan Krish
Krishanthan Krish - avatar
1 Answer
+ 2
Add a space before %c to catch remaining white space characters '\n' left in the input stream from previous inputs in this line scanf(" %c",&d); <--- add space like this
29th Nov 2020, 8:30 AM
ChaoticDawg
ChaoticDawg - avatar