To just obtain the length you can write:
int length = snprintf(NULL, 0, "{data:%d}", 12312);
Note that the return type is int
. It may return -1
in case of some sort of error. Make sure your input data doesn't include long strings that might cause the total length to exceed INT_MAX
!