Question

I need to convert a char array into int and float using C The array is like this

char* text = "15.34";

I also need to convert a float/int back into an array again

Was it helpful?

Solution

You can use sscanf also. For example:

float fp = 0; sscanf( text, "%f", &fp );

To convert back use sprintf()

OTHER TIPS

Use atoi()/strtol() and atof()/strtod() library functions to convert from string.

To convert back use sprintf() with %d and %f format specifiers.

Take a look at sscanf() and sprintf().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top