defensive-coding-guide/modules/ROOT/examples/C-String-Functions-snprintf-incremental.adoc
2022-01-13 20:42:40 +01:00

10 lines
262 B
Text

char buf[512];
char *current = buf;
const char *const end = buf + sizeof(buf);
for (struct item *it = data; it->key; ++it) {
snprintf(current, end - current, "%s%s=%d",
current == buf ? "" : ", ", it->key, it->value);
current += strlen(current);
}