Home > database >  What does atof stand for?
What does atof stand for?

Time:05-14

In C atof=a-to-f(loat) converts a string into a double precision float. I am wondering what the a part of atof stand for.

CodePudding user response:

atof is a function in the C programming language that converts a string into a floating point numerical representation. atof stands for ASCII to float. It is included in the C standard library header file stdlib.h. Its prototype is as follows

double atof (const char *str);

The str argument points to a string, represented by an array of characters, containing the character representation of a floating point value. If the string is not a valid textual representation of a double, atof will silently fail, returning zero (0.0) in that case. [1]

Note that while atoi and atol return variable types corresponding with their name ("atoi" returns an integer and "atol" returns a long integer), atof however, does not return a float, it returns a double.

A related function is sscanf. This function extracts values from strings and its return argument is the number of valid values it managed to extract (so, unlike atof, sscanf can be used to test if a string starts with a valid number).

CodePudding user response:

To best answer what the a stands for, go back to early 1970s when bytes cost approached dollars each.

Even if a originally stood for ASCII, atof() did not mean to convert ASCII into double as the implementation may have used an alternate character encoding. With EBCDIC or PETSCII, one could think of a as alpha and write code for atof() per that non-ASCII encoding.

  • Related