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
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
What is the default value of local and global variables in c?
Why is it that not all header files are declared in every C program?
What is the difference between array and pointer in c?
What does printf does?
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.
Which header file is essential for using strcmp function?
What is the difference between exit() and _exit() function in c?
Define circular linked list.
Can you define which header file to include at compile time?
Write a program to generate the Fibinocci Series
What is a stream water?
can any one please explain, how can i access hard disk(physical address)? it is possible by the use of far,near or huge pointer? if yes then please explain......
How can I find out if there are characters available for reading?
What is pivot in c?