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
Explain what are the advantages and disadvantages of a heap?
Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result
Can stdout be forced to print somewhere other than the screen?
Why do we need arrays in c?
When can a far pointer be used?
What is a header file?
When can you use a pointer with a function?
Explain what does the function toupper() do?
What are the features of c languages?
What is the difference between memcpy and memmove?
Is that possible to store 32768 in an int data type variable?
What’s the special use of UNIONS?
How are pointers declared in c?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
What the advantages of using Unions?