title: Reading float using scanf in c
body: <p>i have a structure which contains a float variable,</p>
  
  <pre><code>struct MyStruct{
      float p;
  }newMyStruct;
  </code></pre>
  
  <p>And i am reading a value into it using <code>scanf</code></p>
  
  <pre><code>int main(){
      scanf("%f",&amp;(newMyStruct.p));
  }
  </code></pre>
  
  <p>The problem is when i print it using <code>printf("%f",newMyStruct.p)</code> it prints '0.000000'. Also i get a warning that says the arugment is double while the format expects it to be float(warning for the <code>scanf("%f",&amp;(newMyStruct.p));</code> statement).When i change <code>scanf()</code> syntax to
  <code>scanf("%0f",&amp;(newMyStruct.p));</code>,<code>printf("%0f",newMyStruct.p);</code> prints the float value correctly but the compiler gives another warning(something related to precision being 0).
  Also <code>printf("%2f",newMyStruct.p)</code> prints the float number in some other format.</p>
  
  <p>So, my question is how do i get rid of all these warnings and read a proper float variable which can be properly printed as well.</p>
  
  <p>I dont have access to the laptop i generally code on and hence i cannot provide proper warnings. </p>