/ , sprintf , , .
What you do is create a temporary file with tmpfile (), fprintf () before it (which reliably returns the number of bytes written), then rewind and read all the text or part of the text to the clipboard.
Example:
int my_snprintf(char *buf, size_t n, const char *fmt, ...)
{
va_list va;
int nchars;
FILE *tf = tmpfile();
va_start(va, n);
nchars = vfprintf(tf, fmt, va);
if (nchars >= (int) n)
nchars = (int) n - 1;
va_end(va);
memset(buf, 0, 1 + (size_t) nchars);
if (nchars > 0)
{
rewind(tf);
fread(buf, 1, (size_t) nchars, tf);
}
fclose(tf);
return nchars;
}
finnw source
share