Where did the name `atoi` come from?
Asked Answered
H

2

124

In the C language where did they come up with the name atoi for converting a string to an integer? The only thing I can think of is Array To Integer for an acronym but that doesn't really make sense.

Honorable answered 26/5, 2010 at 2:22 Comment(1)
For many years, I always read this as if it were a word in French, pronounced like "ah-twah" and never considered its provenance. I was baffled when I first heard someone read it as "ay-too-eye". And then it all made sense.Stratification
S
205

It means Ascii to Integer. Likewise, you can have atol for Ascii to Long, atof for Ascii to Float, etc.

A Google search for 'atoi "ascii to integer"' confirms this on several pages.

I'm having trouble finding any official source on it... but in this listing of man pages from Third Edition Unix (1973) collected by Dennis Ritchie himself, it does contain the line:

atoi(III): convert ASCII to integer

In fact, even the first edition Unix (ca 1971) man pages list atoi as meaning Ascii to Integer.

So even if there isn't any documentation more official than man pages indicating that atoi means Ascii to Integer (I suspect there is and I just haven't been able to locate it), it's been Ascii to Integer by convention at least since 1971.

Soble answered 26/5, 2010 at 2:23 Comment(5)
Does the 1979 Version 7 Unix Manual count as an official source? cm.bell-labs.com/7thEdMan/vol1/man3.bunYost
I guess the man pages are as official as it gets. I was expecting it to be declared in one of the standards, at least, but it's not in the C99 draft standard that I have...Soble
Misnamed then, since as soon as C hit IBM machines, their implementations of the function would have converted EBCDIC to integer :-)Halidom
damn... the people behind Go seem to be really conservative in some aspectsBobker
@Honorable since C doesn't have automatic memory management, returning a pointer to a string is risky business. It's very easy to forget to free() if you can't see a malloc(). Unlike atoi(), such a function couldn't be used within a larger expression—you would have to assign it to a variable immediately, so that you can free it later. Strings are a pain in C so they're mostly used for I/O. If you want to strcat a number... just use sprintf instead. If you want to print or save it, use [f]printf. If you have a problem with this you are probably using C for a job it wasn't designed for.Speck
T
-4

I griefly believe that function atoi means ascii to integer.

Tressa answered 19/12, 2017 at 10:40 Comment(2)
This does not provide an answer to the question. You can search for similar questions, or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, ask a new question, and include a link to this one to help provide context. See: Ask questions, get answers, no distractionsFallonfallout
Please explain what the added value of this answer is in comparison to the much older and upvoted one which starts off with exactly the same information and then goes on explaining with apparently very applicable references. Try to avoid the impression that you have just copied the main content in hope for upvotes on your answer. As a side note what does "griefly" mean and how do you apply that term to this situation?Yaelyager

© 2022 - 2024 — McMap. All rights reserved.