Here is my code as u can see i tried to convert a array (whitch is a char) ro a double if you could tell me a better way to do this or tell me whats wrong with my code i would be ver great full o and btw the code is suposed to convert a bionary number into a decimal
Code:
#include "stdafx.h"
#include "math.h"
void get_string( char buffer[], int size ) ;
void convert (int temp, double array2[]) ;
void main (void)
{
int i = 0;
int temp ;
char array[20] ;
double array2[20];
printf("Please enter in a binary number: ");
get_string (array,20);
for(i=0; array[i]=='\0' ;i++)
{
temp = i ;
}
printf("%i",temp);
for(i =0; i>=20; i++)
{
array[i] = (char)array2[i] ;
}
for(i=0; array[i]!= '\0' ; i++ )
{
convert(temp,array2[i]) ;
}
}
/*
Name : get_string - Allows the user to input a string.
Parameters : buffer - The input string.
*/
void get_string( char buffer[], int size )
{
char character;
int j = 0;
do /* Get a character until newline or */
{ /* we run out of characters. */
character = getchar() ;
buffer[j] = character ;
++j;
}
while ( character != '\n' && j < size ) ;
while ( character != '\n' ) /* Get rid of extra characters. */
character = getchar() ;
buffer[j - 1] = '\0' ; /* Replace newline with the null-byte. */
}
void convert (int temp, double array2[])
{
double temp3 ;
double temp4 ;
int i = 20;
double power =0;
for(i=temp; i>=0 ; i--)
{
temp3 = pow ( array2[i], power) ;
temp4 += temp3 ;
power++ ;
printf("##%lf",temp3);
}
printf("%lf,##%lf\n##%i", temp4,temp3,array2[0] ) ;
}