First change:
char returnData[2048];
to
char returnData[2048] = { '' };
As already mentioned in the comments, you should initialize your Array with Zeros/NUL-Terminator, so the call to strcat
is defined as strcat
replaces the ''
with the src
parameter.
And as some compilers complain use strncat
or similar instead of strcat
.
Also don't forget, that you also need to append '
'
to get the same output as with your printf
.
You could either calculate the length beforehand resulting in two loops
or resize the buffer dynamically.
BTW: Why do you want to store it in a single string?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…