I just begin to learn C and here is my program whose task is to get a value of float number inside a string. The program will stop when meet character '$'. It find where the floating point is located and then using its location as reference to get the value. There's no problem in compiling but when running, , it return 0.000 for any input value
I can't find what's wrong in this program so
here is my code
#include "stdio.h"
float power( int x, int y);
int main()
{
int i=0, e=0;
float x=0;
char str[100];
scanf("%s", str[0]);
for (i=0; i<100; i++){
if (str[i]='.'){
for (e=0; e<i; e++){
x += str[e]*power((i-e-1),10);
}
}
break;
}
i++;
while (str[i]!='$'){
x += str[i]*power((e-i),10); // str[e] == '.'
i++;
}
printf("%f", x);
return 0;
}
float power( int x, int y) //simple power for int base
{
int i, temp;
temp=y
if (x>=0){
for(i=0; i<x; i++){
}
y=y*temp;
}
else{
for(i=0; i>x; i--){
y=1/temp;
}
}
return y;
}