title: Convert char to float in c
body: <p>I need to convert char to float. I know we can do this with the help of atof() function. But I dont want to create another variable to hold the float. I want the converted float to go in the same variable. Like this </p>
  
  <pre>operand = atof(operand)</pre>
  
  <p>Here operand is of type char. I also tried casting like this</p>
  
  <pre>(float)operand = atof(operand)</pre>
  
  <p>but no use.</p>
  
  <p>Here is the entire code :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void main() {
      float operand = 0.0F ;
      char operator = '0' ;
      printf("\nFollowing operators are supported : + - * / S E\n") ;
      float acc = 0.0F ;
      while((operand = getchar()) !=0 &amp;&amp; getchar()==' ' &amp;&amp; (operator = getchar()) != 'E') {
              (float)operand = atof(operand) ;
              switch (operator) {
                      case '+' : printf("\nAdd %f to Accumulator.\tResult : %f\n", operand , operand + acc);
                                 acc+= operand ;
                      break ;
                      case '-' : printf("\nSub %f from Accumulator.\tResult : %f\n", operand, acc - operand);
                                 acc-= operand ;
                      break ;
                      case '*' : printf("\nMultiply Accumulator with %f.\t Result : %f\n", operand, operand * acc);
                                 acc = acc * operand ;
                      break ;
                      case '/' : printf("\nDivide Accumulator by %f.\tResult : %f\n", operand, acc / operand);
                                 acc = acc / operand ;
                      break ;
                      case 'S' : printf("\nSet Accumulator to %f\n",operand) ;
                                 acc = operand ;
                      break ;
                      default : printf("\nInvalid syntax\n") ;
              }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Any help is welcome.</p>