Well, first of all, please see my comment to the question.
Replace the function
printf
with
sprintf
which "prints" to a string:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/[
^].
You can even avoid replacing the function name where it is currently used. Instead, wrap a call to
sprintf
into a function and name it
printf
; use this new function in your legacy code.
When all printing to a string is done, use this string to populate the text box value.
—SA