.\" 386BSD man pages
.\" Modified Sun Jul 25 10:53:39 1993 by Rik Faith (faith@cs.unc.edu)
.\" Added correction due to nsd@bbc.com (Nick Duffek) - aeb, 950610
-.TH STRTOL 3 2015-08-08 "GNU" "Linux Programmer's Manual"
+.TH STRTOL 3 2019-10-10 "GNU" "Linux Programmer's Manual"
.SH NAME
strtol, strtoll, strtoq \- convert a string to a long integer
.SH SYNOPSIS
.nf
.B #include <stdlib.h>
-.sp
+.PP
.BI "long int strtol(const char *" nptr ", char **" endptr ", int " base );
-.sp
+.PP
.BI "long long int strtoll(const char *" nptr ", char **" endptr \
", int " base );
.fi
-.sp
+.PP
.in -4n
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.in
-.sp
+.PP
.ad l
.BR strtoll ():
.RS 4
If
.I base
is zero or 16, the string may then include a
-"0x" prefix, and the number will be read in base 16; otherwise, a
+"0x" or "0X" prefix, and the number will be read in base 16; otherwise, a
zero
.I base
is taken as 10 (decimal) unless the next character
(and returns 0).
In particular, if
.I *nptr
-is not \(aq\\0\(aq but
+is not \(aq\e0\(aq but
.I **endptr
-is \(aq\\0\(aq on return, the entire string is valid.
+is \(aq\e0\(aq on return, the entire string is valid.
.PP
The
.BR strtoll ()
.TP
.B ERANGE
The resulting value was out of range.
-.LP
+.PP
The implementation may also set
.IR errno
to
.SH CONFORMING TO
.BR strtol ():
POSIX.1-2001, POSIX.1-2008, C89, C99 SVr4, 4.3BSD.
-
+.PP
.BR strtoll ():
POSIX.1-2001, POSIX.1-2008, C99.
.SH NOTES
and then determine if an error occurred by checking whether
.I errno
has a nonzero value after the call.
-
+.PP
According to POSIX.1,
in locales other than the "C" and "POSIX",
these functions may accept other,
implementation-defined numeric strings.
-.LP
+.PP
BSD also has
-.sp
+.PP
.in +4n
-.nf
+.EX
.BI "quad_t strtoq(const char *" nptr ", char **" endptr ", int " base );
-.sp
+.EE
.in
-.fi
+.PP
with completely analogous definition.
Depending on the wordsize of the current architecture, this
may be equivalent to
has a simpler interface than
.BR strtol ().)
Some examples of the results produced by this program are the following:
+.PP
.in +4n
-.nf
-
+.EX
.RB "$" " ./a.out 123"
strtol() returned 123
.RB "$" " ./a.out \(aq 123\(aq"
No digits were found
.RB "$" " ./a.out 4000000000"
strtol: Numerical result out of range
-.fi
+.EE
.in
.SS Program source
\&
-.nf
+.EX
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
long val;
if (argc < 2) {
- fprintf(stderr, "Usage: %s str [base]\\n", argv[0]);
+ fprintf(stderr, "Usage: %s str [base]\en", argv[0]);
exit(EXIT_FAILURE);
}
}
if (endptr == str) {
- fprintf(stderr, "No digits were found\\n");
+ fprintf(stderr, "No digits were found\en");
exit(EXIT_FAILURE);
}
/* If we got here, strtol() successfully parsed a number */
- printf("strtol() returned %ld\\n", val);
+ printf("strtol() returned %ld\en", val);
- if (*endptr != \(aq\\0\(aq) /* Not necessarily an error... */
- printf("Further characters after number: %s\\n", endptr);
+ if (*endptr != \(aq\e0\(aq) /* Not necessarily an error... */
+ printf("Further characters after number: %s\en", endptr);
exit(EXIT_SUCCESS);
}
-.fi
+.EE
.SH SEE ALSO
.BR atof (3),
.BR atoi (3),
.BR atol (3),
.BR strtod (3),
-.BR strtoul (3)
+.BR strtoimax (3),
+.BR strtoul (3),