I wrote a very simple C function to illustrate what I would like to simplify:
void main(int argc, char *argv[])
{
char *me = "Foo";
char *you = "Bar";
char us[100];
memset(us, 100, 0x00);
sprintf(us, "You: %s\n", you);
sprintf(us + strlen(us), "Me: %s\n", me);
sprintf(us + strlen(us), "We are %s and %s!\n", me, you);
printf(us);
}
Is there a standard library function to handle what I'm doing with sprintf
and advancing the pointer?
sprintf
returns the number of non-NUL characters written.
int len = 0;
len += sprintf(us+len, ...);
len += sprintf(us+len, ...);
...
char *me="Foo";
char *you="Bar";
char us[100];
char* out = us;
out += sprintf(out,"You: %s\n",you);
out += sprintf(out,"Me: %s\n",me);
out += sprintf(out,"We are %s and %s!\n",me,you);
printf("%s", us);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With