Borland C++ reference

atol

raw OCR

Converts a string to a long.

Defined in header <stdlib.h>

Syntax

#include <stdlib.h>
long atol(const char *s);

Portability

DOSUNIXWindowsANSI CC++ only
■■■■

Remarks

atol converts the string pointed to by s to long, atol recognizes (in the following order)

B an optional string of tabs and spaces B an optional sign B a string of digits

The characters must match this generic format:

[ws] [sn] [ddd]

In this function, the first unrecognized character ends the conversion.

There are no provisions for overflow in atol (results are undefined).

Return value

atol returns the converted value of the input string. If the string cannot be converted to a number of the corresponding type (long), atol returns 0.

See also

Example

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   long 1;
   char *lstr = "98765432";
   1 = atol(lstr);
   printf("string = %s long = %ld\n",  Istr, 1);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.