Main index | Section 3 | Options |
#include <stdlib.h>
The string may begin with an arbitrary amount of whitespace (as determined by isspace(3)) followed by a single optional ‘+’ or ‘-’ sign.
The remainder of the string is converted to a long long value according to base 10.
The value obtained is then checked against the provided minval and maxval bounds. If errstr is non-null, strtonum() stores an error string in *errstr indicating the failure.
int iterations; const char *errstr;iterations = strtonum(optarg, 1, 64, &errstr); if (errstr != NULL) errx(1, "number of iterations is %s: %s", errstr, optarg);
The above example will guarantee that the value of iterations is between 1 and 64 (inclusive).
[ERANGE] | |
The given string was out of range. | |
[EINVAL] | |
The given string did not consist solely of digit characters. | |
[EINVAL] | |
The supplied minval was larger than maxval. | |
If an error occurs, errstr will be set to one of the following strings:
too large | The result was larger than the provided maximum value. |
too small | The result was smaller than the provided minimum value. |
invalid | The string did not consist solely of digit characters. |
STRTONUM (3) | April 29, 2004 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems. | ” |
— Jamie Zawinski |