Bill Cunningham said:
I have used strtol before Keith and I've never used limits.h
myself. And I've never heard of the LONG... macros until I actually
looked at my man page. Could I use 0 to report an error? I might
just use atoi instead.
Ok, you've never used limits.h before. So you can use it now.
Just add "#include <limits.h>" to the top of your program.
It's trivial.
You were trying to use LONG_MAX and LONG_MIN. Several of us assumed
that it would be very easy to find out where they're defined,
but it turned out to be more difficult than we thought (the man
page you cited wasn't clear, and the index of K&R2 points to the
wrong place). You probably could have checked some other reference
or done a Google search, but whatever.
You now know that LONG_MAX and LONG_MIN are defined in <limits.h>
and the strtol function is declared in <stdlib.h>. Your question
has been answered.
Could you use 0 to report an error? I suppose so, but why on Earth
would you want to? 0 is typically a valid value.
You could use atoi if you wanted to, but you'd lose the possibility
of any real error checking, and you'd be throwing away all the
work you've done trying to use strtol. In a real-world program,
strtol is the right function to use here. If you give up now,
everything you've done so far will have been a collosal waste of
time, yours as well as ours. (It may have been anyway.)
Have you even *tried* to fix the errors in your program, or are you
just going to drop it and come back later with some other problem?
Fix your code or stop wasting our time.