home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!hubcap!ncrcae!ncrhub2!ncrgw2!psinntp!heimdall!thor!scjones
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.lang.c
- Subject: Re: strtol() return values
- Message-ID: <575@heimdall.sdrc.com>
- Date: 27 Jan 93 14:27:08 GMT
- References: <ric.728002623@updike>
- Sender: news@heimdall.sdrc.com
- Lines: 21
-
- In article <ric.728002623@updike>, 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.
-
- The second argument to strtol is the address of a pointer which strtol
- sets to point to the first character following the converted string.
- If, after calling strtol, that pointer is equal to the pointer to the
- string you asked strtol to convert, then strtol didn't find a valid
- string to convert. For example:
-
- #include <stdlib.h>
- char *buf, *endptr;
- long val;
- ...
- val = strtol(buf, &endptr, 0);
- if (endptr == buf) { /* buf did not point to a valid string */ }
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- It seems like once people grow up, they have no idea what's cool. -- Calvin
-