Well, the biggest part of you loop can be replaced with an sscanf() and then a "smart" sprintf. There is no need for any memory allocation on the heap (as is done through all these string manipulation methods) since the final string you are trying to build has a finite size (less than 100 bytes).

Could you please supply some examples of the externally provided strings (those you store in the myStruct structure?

Regards,

--harizak