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
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
In which header file is the null macro defined?
What is assignment operator?
Is c still relevant?
What is the difference between #include and #include 'file' ?
Explain the term printf() and scanf() used in c language?
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
What is the heap?
Explain the use of function toupper() with and example code?
What is the use of header?
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
Which is better malloc or calloc?
i have to apply for rbi before that i need to know the the syllabus for the entrance questions. whethet it may be aps or techinical
What are the different properties of variable number of arguments?
Calculate the weighted average of a list of n numbers using the formula xavg = f1x1+f2x2+ ….+ fnxn where the f’s are fractional weighting factors, i.e., 0<=fi<1, and f1+f2+….+fn = 1