home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!hobbes!md
- From: md@sco.COM (Michael Davidson)
- Subject: Re: strtol() return values
- Organization: The Santa Cruz Operation, Inc.
- Date: Tue, 26 Jan 1993 12:36:14 GMT
- Message-ID: <1993Jan26.123614.10840@sco.com>
- References: <ric.728002623@updike>
- Sender: news@sco.com (News admin)
- Lines: 16
-
-
- 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?
-
- Yes - try something like this:
-
- char **p;
-
- if ((value = strtol(str, p, 0)) == 0 && *p == str)
- printf("strtol() failed!!\n");
-
-