title: Converting a number from a given base to base 10
body: <p>I am trying to convert from any base to base 10. For an input of 010111 base 2 it gives me 1, and for 35 base 9 it gives me 18 which should be 38. Any suggestions?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  #include&lt;string.h&gt;
  
  #define LENGTH 6
  
  double pow( double x, double power );
  
  int main()
  {
      char input[LENGTH+1] ;
      int base;
      unsigned decValue ;
      char values[] = "0123456789ABCDEFG";
      int i;
  
      puts( "Enter a value, and its base: " );
      scanf( "%s", &amp;input );
      scanf( "%i", &amp;base );
  
      for( i = LENGTH-1 ; i &gt;= 0; i-- )
      {       
          int index = strchr(values, input[ i ] ) - values;
  
          decValue += index * pow( base , i - LENGTH + 1 );
      }
  
      printf( "%s (base-%u) equals %u \n", input, base, decValue );
  
  
      return 0;
  }
  </code></pre>