Write an implementation of “float stringToFloat(char *str).”
The code should be simple, and not require more than the
basic operators (if, for, math operators, etc.).
• Assumptions
• Don’t worry about overflow or underflow
• Stop at the 1st invalid character and return the number
you have converted till then, if the 1st character is
invalid return 0
• Don’t worry about exponential (e.g. 1e10), instead you
should treat ‘e’ as an invalid character
• Write it like real code, e.g. do error checking
• Go though the string only once
• Examples
• “1.23” should return 1.23
• “1a” should return 1
• “a”should return 0

Answer Posted / fernando

If I have character buffer with many floats and want to
separate it as I do?

Example:

for (uint8_t i = 0; i < n; i++)
{
buf [i]; 25.45, 26.54,...
}
buf[0]=
buf[1]=
.
.
.
buf[n]=

Thanks.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where in memory are my variables stored?

639


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

786


Why do we use stdio h and conio h?

645


what are bit fields? What is the use of bit fields in a structure declaration?

1503


Explain high-order bytes.

678






What are header files and explain what are its uses in c programming?

618


List out few of the applications that make use of Multilinked Structures?

1312


Write programs for String Reversal & Palindrome check

601


Is c procedural or functional?

593


What are the differences between Structures and Arrays?

614


How can I send mail from within a c program?

586


Explain the use of function toupper() with and example code?

660


What are structural members?

576


What is the advantage of c?

613


How can a process change an environment variable in its caller?

658