Use not strf, but the equivalent C function sprintf, with a string of the desired length that you allocated before with malloc.