Show: Object Pascal C++
Display Preferences

atol, _wtol

From Appmethod Topics
Jump to: navigation, search

Go Up to stdlib.h Index


Header File

stdlib.h

Category

Conversion Routines, Math Routines

Prototype

long atol(const char *s);
long _wtol(const wchar_t *s);

Description

Converts a string to a long.

  • atol converts the string pointed to by s to long. atol recognizes (in the following order)
  • An optional string of tabs and spaces
  • An optional sign
  • 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 (b), atol returns 0.

Example

#include <stdlib.h>
#include <stdio.h>
int main(void)
{
   long l;
   char *lstr = "98765432";
   l = atol(lstr);
   printf("string = %s integer = %ld\n", lstr, l);
   return(0);
}

Portability

POSIX Win32 ANSI C ANSI C++

atol

+

+

+

+

_wtol

+

Personal tools
In other languages