I am using snprintf to concatenate a string to a char array:
char buf[20] = \"\";
snprintf(buf, sizeof buf, \"%s%s\", buf, \"foo\");
printf(\"%s\\n\", buf);
Why not use strncat()? It was designed to do exactly this:
char buf[20] = "";
strncat(buf, "foo", sizeof buf);
printf("%s\n", buf);
strncat(buf, " bar", sizeof buf - strlen(buf));
printf("%s\n", buf);
If your systems supports it you can use strncat_s() instead of strncat, as it has an additional level of overflow protection and avoids the need for calculating the number of bytes remaining in the output buffer.
If you must use snprintf, you will need to create a separate pointer to keep track of the end of the string. This pointer will be the first argument that you pass to snprintf. Your current code always uses buf, which means that it will always print to the beginning of that array. You can either use strlen to find the end of the string after each snprintf call, or you can use the return value of snprintf to increment the pointer.