NETWORKSTelecom Networks

Convert A String To A Double, Int Or Long Int With atof(), atoi() or atol() | C Programming Tutorial

How to convert a string to a double, int, or long int value in C using the atof(), atoi() and atol() functions available in stdlib.h. Source code: https://github.com/portfoliocourses/c-example-code/blob/main/convert_string.c. Check out https://www.portfoliocourses.com to build a portfolio that will impress employers!

source

atoll logiciel

8 thoughts on “Convert A String To A Double, Int Or Long Int With atof(), atoi() or atol() | C Programming Tutorial

  • In long int value I gets a negative value..is there any solutions??

  • hey am kinda new so i might ask something stupid b why the atof function need the char to have the *? like why char *double_test and not char double_test what does the * do?

  • This is not really a "wholesome" resolution. The ato.() functions, while convenient and simple, can result in undefined behavior like failing to convert correctly or mistaking a hex number, etc. The strto.() family of functions are a lot safer albeit requiring three arguments (the string, a pointer to where in your input string the conversion stopped, and the base you wish to convert to.)

  • Thank you for zooming in, it makes it so much easier

  • Thank you for this. I'm looking for how to do the reverse which is converting like a long to string type

Comments are closed.