Tool/software: Code Composer Studio
Hi all,
I'm working on extracting a real number out of a string (an array of characters). I wrote a function to do this, and during debug I realized that a variable of float (to hold the extracted real number) was not created as I expected it to. Can anyone help me to fix it. Thank you!
P/s: the tem variable was also not created until I initialized it with "long tem = 0;"
float realnum_extractor(char array[], unsigned int i){
unsigned int j, k;
long tem = 0;
float real1 = 0;
for(j = i; array[j] != '.'; j++); //to get no. of digits to the left of "."
for(k = i; array[k] != ','; k++); //to get no. of digits
k--; //"." does not count
for(i; i < j; i++){
tem += (array[i]-48)*pow(10,k-i-1);
}
for(i = j + 1; i <= k; i++){
tem += (array[i]-48)*pow(10,k-i);
}
real1 = (float) tem/pow(10,k-j);
return real1;
}