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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!hobbes!md
  3. From: md@sco.COM (Michael Davidson)
  4. Subject: Re: strtol() return values
  5. Organization: The Santa Cruz Operation, Inc.
  6. Date: Tue, 26 Jan 1993 12:36:14 GMT
  7. Message-ID: <1993Jan26.123614.10840@sco.com>
  8. References: <ric.728002623@updike>
  9. Sender: news@sco.com (News admin)
  10. Lines: 16
  11.  
  12.  
  13. ric@updike..sri.com (Richard Steinberger) writes:
  14.  
  15. >    strtol() returns a long int when successful.  If a non-numeric
  16. >string is encountered, 0 is returned.  Unfortunately, errno doesn't seem
  17. >to be set.  Here's the question:  If a string like, "0" or "000"
  18. >is encountered, I also get a 0 returned from strtol(). Is there an easy,
  19. >elegant way to check for this without examing each char?  
  20.  
  21. Yes - try something like this:
  22.  
  23.     char    **p;
  24.  
  25.     if ((value = strtol(str, p, 0)) == 0 && *p == str)
  26.         printf("strtol() failed!!\n");
  27.  
  28.