Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
checking for errors using strtod in C
Im writing a C program that accepts some values as command line arguments and performs some calculations on them.
I need the strings read form the command line to be converted to float or double (whichever). That's not a problem. Using either atof() or strtof() (or atod() and strtod()) works fine.
My main problem is trying to handle the error if the user does not enter a floating poin value. I read the specification for strtod() to capture errors but i can't make head or tail of it. Could someone please explain how the error checking part of these functions works?
(e.g.: if the user enters "hello" instead of "5.54353" i need to be able to respond and print and error message saying "floating point value not entered".)
Thanks in advance.
0 · ·