Posts

Showing posts with the label Atof

Atoi Implementation In C

Answer : << is bit shift, (k<<3)+(k<<1) is k*10 , written by someone who thought he was more clever than a compiler (well, he was wrong...) (*p) - '0' is subtracting the value of character 0 from the character pointed by p , effectively converting the character to a number. I hope you can figure out the rest... just remember how the decimal system works. Here is a specification for the standard function atoi . Sorry for not quoting the standard, but this will work just as fine (from: http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/ ) The function first discards as many whitespace characters (as in isspace ) as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many base-10 digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral n...