Saving formatted data in C
3 answers
Use sprintf()
. Remember to allocate a large enough buffer for the array. Like this:
char buf[24];
sprintf(buf, "My age is = %d", age);
24 char
are long enough to contain the result here, regardless of the value age
. I am assuming that age
is a 32 bit integer.
Of course, if you change the text for something longer, you will have to increase the buffer size.
0
a source to share