Re: question




"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:lnabdx864e.fsf@xxxxxxxxxxxxxxxxxx

If argc is not equal to 5, you print an error message *and then
continue with the rest of the program, using garbage input*.

strtod is capable of telling you about errors. Use that capability.
Don't ask us how; look it up.

atoi() is *not* capable of telling you about errors. Use strtol()
instead. And check for errors.

For every standard function you use, you must have a #include
directive for the corresponding header.

Ah Keith good to hear from you. I have changed that if statement to include
an exit(EXIT_FAILURE) call so the program exits and there's no seg fault.
I am just used to using atoi. So there's no error checking. I haven't
included that at all in this program I usually do that with streams and
such. It would be a good thing to start. I'll check out strtol.

Bill


.



Relevant Pages

  • Re: how to pass float value from argv?
    ... It clearly says that both atoi() and atof() has been ... deprecated by strtol() and strtod() ...
    (comp.lang.c)
  • Re: Check all errors in code?
    ... The atoi function converts the initial portion of the string ... pointed to by nptr to int representation. ... The atoi function returns the converted value. ... The strtol function returns the converted value, ...
    (comp.lang.c)
  • Re: How to find string contains a numeric value
    ... strtol & strtod returns 0 on failure and my string can contains ... string contains a numeric value. ... To make squirrel pie, first catch your squirrel. ...
    (comp.lang.c)
  • Re: How to find string contains a numeric value
    ... strtol & strtod returns 0 on failure and my string can contains zero ... All your questions are answered by the documentation of strtol ... Neither strtolnor strtodis capable of deciding whether a string ...
    (comp.lang.c)
  • Re: how to pass float value from argv?
    ... Calls to atoi() and atol() might be faster than correspond- ... ing calls to strtol(), and calls to atoll() might be faster ...
    (comp.lang.c)