Misplaced Pages

Atoi: Difference between revisions

Article snapshot taken from[REDACTED] with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 22:28, 5 August 2010 editRichfife (talk | contribs)Extended confirmed users7,113 edits You'd have to make a special effort to write a non-thread safe atoi(), but, yes, the reference supports the claim that it's happened at least once.← Previous edit Revision as of 13:03, 19 August 2010 edit undo1exec1 (talk | contribs)Pending changes reviewers, Rollbackers50,085 editsm copy-editedNext edit →
Line 1: Line 1:
{{lowercase|title=atoi}} {{lowercase|title=atoi}}
The '''atoi''' ('''A'''SCII '''to''' '''i'''nteger) function in the ] is used to convert a string into a numerical representation. '''atoi''' ('''A'''SCII '''to''' '''i'''nteger) is a function in the ], which is used to convert a string into a numerical representation.


:<code>int '''atoi'''(const char *str) </code> :<code>int '''atoi'''(const char *str) </code>

Revision as of 13:03, 19 August 2010

atoi (ASCII to integer) is a function in the C programming language, which is used to convert a string into a numerical representation.

int atoi(const char *str)

The str argument is a string, represented by an array of characters, containing the characters of a signed integer number. The string must be null-terminated. When atoi encounters a string with no numerical sequence, it returns zero (0). If the string holds a valid sequence of digits that represents the number 0, it also returns a 0, making it impossible to tell from the return value alone whether the string holds a valid number or not. The newer function strtol does not have this deficiency.

Other problems of atoi are that it is not thread-safe and not async-cancel safe on some operating systems.

Variants of the atoi function, atol, atof, and atoll (the latter formerly known as atoq), are used to convert a string into a long, double, or long long type, respectively:

long atol(const char *str)
double atof(const char *str)
long long atoll(const char *str) (C99)

Standards conformance

The atoi, atof, and atol functions are a part of the ISO standard C library (C89), while the atoll function is added by C99.

However, because of the ambiguity in returning 0 and lack of thread-safety and async-cancel safety on some operating system, atoi is considered to be deprecated by strtol.

References

The Version 7 Unix Manual Pages © 1979 by Bell Telephone Laboratories, Incorporated.

The Version 1 Unix Manual page for atoi written by Ken Thompson (November 1971).

  1. ^ http://www.codecogs.com/reference/c/stdlib.h/atoi.php


See also

Categories:
Atoi: Difference between revisions Add topic