| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: Variable arguments |
-=> Quoting Owen Kaluza to All <=-
Hello Owen,
OK> I am writing a library of functions to include in my programs
OK> with similar tasks to those in CONIO.H but using direct video
OK> output.
OK> I have struck problems in trying to write a version of printf().
OK> My idea was to write a function called dprintf() which accepted
OK> the arguments, used sprintf() to format them and store in a
OK> buffer and then output the resulting string to the screen.
OK> I don't know how the variable argument system works that
OK> printf() uses so I am unable to pass the values on to sprintf().
Check the routine below for ideas. Instead of using vfprintf, you
would use vsprintf, which has identical syntax.
/* ************************************************* */
/* FERRORF.C
** Prints error message with printf() formatting syntax, then a colon,
** then a message corressponding to the value of errno, then a newline.
** Output is to filehandle.
**
** Public Domain by Mark R. Devlin, free usage is permitted.
*/
#include
#include
#include
#include
int ferrorf(FILE *filehandle, const char *format, ...)
{
int vfp, fp;
va_list vargs;
vfp = fp = 0;
va_start(vargs, format);
vfp = vfprintf(filehandle, format, vargs);
va_end(vargs);
fp = fprintf(filehandle, ": %s\n", sys_errlist[errno]);
return ((vfp==EOF || fp==EOF) ? EOF : (vfp+fp));
}
/* ************************************************* */
I hope this gets you started in the right direction. If you want to
know more about stdarg stuff, just ask.
Michael Stapleton of Graphic Bits.
* AmyBW v2.10 *
... This tagline is encrypted
--- Blue Wave/RA v2.10 AmyBW
* Origin: The Three Amigas - better than two (3:713/615.0)SEEN-BY: 50/99 620/243 623/630 711/401 409 410 413 430 510 807 808 809 932 SEEN-BY: 711/934 712/508 515 713/111 317 601 611 615 618 700 826 888 906 914 SEEN-BY: 714/906 800/1 7877/2809 @PATH: 713/615 888 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™.