I'm not quite sure how to explain this.
I've got some string pointers which need to be filled with an unknown length string at run-time. What I'm having trouble with, is the best way to populate those strings.
For example, I have a string pointer, which I'd like to populate thusly:
sprintf(strptr2,"this string: %s is my %dth attempt at this", strptr1, int1);
I know I need to Malloc or realloc to set the size of strptr2 before I sprintf to it. But how do I get the size?
strlen ("this string: %s is my %dth attempt at this", strptr1, int1); doesn't work, though it's be nice if it did.
I know I could make a fixed length string and sprintf to it, but in my application, the necessary length will be wildly variable.
Is there an automatic way to make my own functions handle getting passed ("%d", int1) type of stuff?
I know I'm missing something.