Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
You can use sscanf also. For example:
float fp = 0; sscanf( text, "%f", &fp );
To convert back use sprintf()
Add a comment
Use atoi()/strtol() and atof()/strtod() library functions to convert from string.
atoi()
strtol()
atof()
strtod()
To convert back use sprintf() with %d and %f format specifiers.
sprintf()
%d
%f
Take a look at sscanf() and sprintf().
sscanf()
sprintf().
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.