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 / nikita
The above two solutions do not take care of the numberes
after the decimal.
for eg; "123.78" would return 123.0000 instead it should
return 123.78.
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is the newline escape sequence?
What is signed and unsigned?
What are the different types of linkage exist in c?
What is difference between structure and union with example?
Define circular linked list.
why programs in c are running with out #include
If you know then define #pragma?
what is recursion in C
What is a floating point in c?
What is putchar() function?
what is bit rate & baud rate? plz give wave forms
How can I access an I o board directly?
What does char * * argv mean in c?
What is meant by errors and debugging?
What does != Mean in c?