title: How to convert a String to a Float in C
body: <p>I have written the following code</p>
  
  <pre><code>#include &lt;stdio.h&gt;      
  #include &lt;stdlib.h&gt; 
  int main()
  
  {
      // declaration of variables as strings
      char astr;
      char bstr;
      char cstr;
  
      /* Input three sides of a triangle */
      printf("Enter first side of triangle: ");
      scanf("%s",&amp;astr);
      printf("Enter second side of triangle: ");
      scanf("%s",&amp;bstr);
      printf("Enter third side of triangle: ");
      scanf("%s",&amp;cstr);
  
      // conversion of strings to float
      float a = atof(&amp;astr);
      float b = atof(&amp;bstr);
      float c = atof(&amp;cstr);
      // checking if given triangle is valid
      if((a + b &gt; c) &amp;&amp; (a + c &gt; b) &amp;&amp; (b + c &gt; a))
      {
         // Checking for special cases of triangle
  
          if(a==b &amp;&amp; b==c)
          {
              /* If all sides are equal */
              printf("Equilateral triangle.");
          }
          else if(a==b || a==c || b==c)
          {
              /* If any two sides are equal */
              printf("Isosceles triangle.");
          }
          else
          {
              /* If none sides are equal */
              printf("Scalene triangle.");
          }
      }
      else
      {
          printf("Triangle is not valid. \n");
      }
  
      printf("%f \n", a);
      printf("%f \n", b);
      printf("%f \n" ,c);
      return 0;
  }
  </code></pre>
  
  <p>However when I run it, I get "Triangle is not valid" despite the fact that mathematically the triangle would be valid</p>
  
  <p>When printing the Values stored in a b and c I discover that only the Value for c is stored correctly but a and b are always 0.000000</p>
  
  <p>what have I done wrong?</p>
  
  <p>Thanks in advance</p>