| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Variable arguments |
> I am writing a library of functions to include in my programs
> with similar tasks to those in CONIO.H but using direct video
> output.
Like cprintf()?
> I have struck problems in trying to write a version of printf().
> My idea was to write a function called dprintf() which
> accepted the arguments, used sprintf() to format them and store
> in a buffer and then output the resulting string to the screen.
> I don't know how the variable argument system works that printf()
> uses so I am unable to pass the values on to sprintf().
There's a generic interface called v?printf() which will probably help.
To provide a brief example:
#include
#include
int dprintf(char const * fmt, ...)
{
int rc;
va_list argp;
char buf[1024];
va_start(argp, fmt);
rc = vsprintf(buf, fmt, argp);
va_end(argp);
output(buf); // Output the string
return rc;
}
ISO will soon to introducing a new interface to the v?printf() family
called v?nprintf(), where you can specify the destination buffer size and
therefore avoid buffer overflow - something that you can only guard against
currently by defining large buffers. No compilers that I am currently aware
of include it (yet).
---
* Origin: Unique Computing, Melbourne, Australia (3:632/348)SEEN-BY: 50/99 620/243 623/630 632/103 348 998 633/371 634/384 388 635/301 SEEN-BY: 635/502 503 544 727 639/100 711/401 409 410 413 430 510 807 808 809 SEEN-BY: 711/932 934 712/515 713/888 714/906 800/1 7877/2809 @PATH: 632/103 348 635/503 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.