home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20241 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.0 KB  |  28 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: strtol() return values
  5. Message-ID: <1993Jan26.171631.22789@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <ric.728002623@updike>
  8. Date: Tue, 26 Jan 1993 17:16:31 GMT
  9. Lines: 17
  10.  
  11. ric@updike..sri.com (Richard Steinberger) writes:
  12.  
  13.  
  14. >    strtol() returns a long int when successful.  If a non-numeric
  15. >string is encountered, 0 is returned.  Unfortunately, errno doesn't seem
  16. >to be set.  Here's the question:  If a string like, "0" or "000"
  17. >is encountered, I also get a 0 returned from strtol(). Is there an easy,
  18. >elegant way to check for this without examing each char?  
  19.  
  20. Unfortunately not.  Of course, you don't have to examine the whole
  21. string.  You only have to look at the first non-whitespace
  22. character when the returned value is zero.  If that character is
  23. '0', you have an actual zero value.  If it is null, you had only
  24. whitespace in the string.  Otherwise, it was not a numeric value.
  25. -- 
  26.  
  27. Steve Clamage, TauMetric Corp, steve@taumet.com
  28.