by Dinesh Thakur Category: Function and Pointer

The atoi, atof and atol utility functions are used to perform string to numeric conversion. As indicated by the last letter in function names, these functions convert the argument string to an integer, floating and long number. Note that the argument string should contain a number of appropriate type as text, optionally preceded by whitespace. For example, the atof function can successfully convert strings such as" 1.23", "3.21El0", etc. The conversion stops when an inappropriate character is encountered in the input string. Thus, these functions will also be able to convert strings such as "-1. 23ABC", "3. 21E10ABc". If conversion is successful, these functions return the converted value, otherwise zero.

The atoi and atol functions convert the argument string to an integer number of type int and long int, respectively. The initial portion of the string should contain an integer number in the decimal format ±ddd, in the range of data type being converted to (i.e., int or long int).

The atof function, on the other hand, converts the argument string to a floating number of type double. The initial portion of the string should contain a floating number in either decimal or scientific notation, in the range of type double.

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles