home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: strtol() return values
- Message-ID: <1993Jan26.171631.22789@taumet.com>
- Organization: TauMetric Corporation
- References: <ric.728002623@updike>
- Date: Tue, 26 Jan 1993 17:16:31 GMT
- Lines: 17
-
- ric@updike..sri.com (Richard Steinberger) writes:
-
-
- > strtol() returns a long int when successful. If a non-numeric
- >string is encountered, 0 is returned. Unfortunately, errno doesn't seem
- >to be set. Here's the question: If a string like, "0" or "000"
- >is encountered, I also get a 0 returned from strtol(). Is there an easy,
- >elegant way to check for this without examing each char?
-
- Unfortunately not. Of course, you don't have to examine the whole
- string. You only have to look at the first non-whitespace
- character when the returned value is zero. If that character is
- '0', you have an actual zero value. If it is null, you had only
- whitespace in the string. Otherwise, it was not a numeric value.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
-