0

I am facing very very strange issue. I am writing very simple program in C.

Program needs to do: read real number and display it on console.

#include <stdio.h>

int main()
{
    double a;
    printf("Give a: ");
    scanf("%f",&a);
    printf("Result for a = %f \n",a);
    return 0;
}

output:

sh-4.3$ gcc -o main *.c                                                                                                                                                                                                                                
sh-4.3$ main                                                                                                                                                                                                                                           
Give a: 123.345                                                                                                                                                                                                                                        
Result for a = 0.000000 

http://goo.gl/4j2Bjv

Why there is 0.0000 instead of my number? Personally I have no idea.... code from this site is working fine.

Any idea?

RMachnik
  • 3,598
  • 1
  • 34
  • 51

1 Answers1

3

Use %lf conversion specification to read a double, %f is for float.

ouah
  • 142,963
  • 15
  • 272
  • 331