Reading float using scanf in c

Edit:

I can’t reproduce the problem. Everything works as expected when I use the following code compiled with gcc:

#include <stdio.h>

struct MyStruct {
  float p;
} newMyStruct;

int main() {
  scanf("%f", &(newMyStruct.p));
  printf("%f\n", newMyStruct.p);
}

The output of gcc –version is as follows:

gcc (Debian 4.7.2-5) 4.7.2

Leave a Comment