Purpose : serialize data in JSON.
Problem : I do not know in advance how many characters a long integer.
I thought a good way to do this is to use sprintf()
size_t length = sprintf(no_buff, "{data:%d}",12312); char *buff = malloc(length); snprintf(buff, length, "{data:%d}",12312);
Of course, I can use a stack variable, for example char a[256] instead of no_buff .
Question: But is C a utility for one-time records like unix /dev/null ? Smth like this:
#define FORGET_ABOUT_THIS ... size_t length = sprintf(FORGET_ABOUT_THIS, "{data:%d}",12312);
ps I know that I can also get the length of an integer through a log, but this way seems more enjoyable.
c printf
alknows
source share