#include <stdlib.h> long int atol(const char *str);
atol
converts the character string str
to a long
integer.
The string should consist of an optional plus or minus sign, followed
by one or more decimal digits. Initial white-space characters are ignored.
atol
returns the integer value represented by the character string,
up to the first unrecognized character. If no initial segment of the
string is a valid integer, the return value is 0L
.
atol
.
If the correct value is too large to be stored in a 370 long
,
either LONG_MAX
(2**31 - 1) or
LONG_MIN
( - 2**31) is returned, depending on the
sign of the value.
#include <stdlib.h> #include <stdio.h> #include <string.h> #define MAXLINE 25 main() { long value; char *input; char line[MAXLINE]; puts("Enter a number: "); input = gets(line); /* If string contains only digits, white space, or +/-, */ /* convert. Note that the input may still not represent */ /* a valid integer. Consider +-14+5. */ if (strspn(input, " +-0123456789") == strlen(input)){ value = atol(input); printf("The long integer equivalent of given string is %ldn", value); } else printf("Invalid count value: %sn", input); }
strtol
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.