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


Please Help Members By Posting Answers For Below Questions

Explain what are the advantages and disadvantages of a heap?

598


Take an MxN matrice from user and then sum upper diagonal in a variable and lower diagonal in a separate variables. Print the result

1469


Can stdout be forced to print somewhere other than the screen?

627


Why do we need arrays in c?

586


When can a far pointer be used?

589






What is a header file?

638


When can you use a pointer with a function?

570


Explain what does the function toupper() do?

636


What are the features of c languages?

632


What is the difference between memcpy and memmove?

606


Is that possible to store 32768 in an int data type variable?

693


What’s the special use of UNIONS?

659


How are pointers declared in c?

602


What is Dynamic memory allocation in C? Name the dynamic allocation functions.

559


What the advantages of using Unions?

674