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

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
  2. From: scjones@thor.sdrc.com (Larry Jones)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strtol() return values
  5. Message-ID: <575@heimdall.sdrc.com>
  6. Date: 27 Jan 93 14:27:08 GMT
  7. References: <ric.728002623@updike>
  8. Sender: news@heimdall.sdrc.com
  9. Lines: 21
  10.  
  11. In article <ric.728002623@updike>, ric@updike..sri.com (Richard Steinberger) writes:
  12. >     strtol() returns a long int when successful.  If a non-numeric
  13. > string is encountered, 0 is returned.  Unfortunately, errno doesn't seem
  14. > to be set.
  15.  
  16. The second argument to strtol is the address of a pointer which strtol
  17. sets to point to the first character following the converted string.
  18. If, after calling strtol, that pointer is equal to the pointer to the
  19. string you asked strtol to convert, then strtol didn't find a valid
  20. string to convert.  For example:
  21.  
  22.     #include <stdlib.h>
  23.     char *buf, *endptr;
  24.     long val;
  25.     ...
  26.     val = strtol(buf, &endptr, 0);
  27.     if (endptr == buf) { /* buf did not point to a valid string */ }
  28. ----
  29. Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH  45150-2789  513-576-2070
  30. larry.jones@sdrc.com
  31. It seems like once people grow up, they have no idea what's cool. -- Calvin
  32.