atoi, _wtoi

De RAD Studio
Aller à : navigation, rechercher

Remonter à Stdlib.h - Index


Header File

stdlib.h

Category

Conversion Routines, Math Routines

Prototype

int atoi(const char *s);

int _wtoi(const wchar_t *s);

Description

Converts a string to an integer.

  • atoi converts a string pointed to by s to int; atoi 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 atoi (results are undefined).

Return Value

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

Example

 #include <stdlib.h>
 #include <stdio.h>
 int main(void)
 {
    int n;
    char *str = "12345.67";
    n = atoi(str);
    printf("string = %s integer = %d\n", str, n);
    return 0;
 }

Portability

POSIX Win32 ANSI C ANSI C++

atoi

+

+

+

+

_wtoi

+