home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.graphics:12901 comp.os.msdos.programmer:11404
- Newsgroups: comp.graphics,comp.os.msdos.programmer
- Path: sparky!uunet!mnemosyne.cs.du.edu!nyx!slindsay
- From: slindsay@nyx.cs.du.edu (Steve Lindsay)
- Subject: Gprintf and setprecision
- Message-ID: <1992Dec15.071041.22208@mnemosyne.cs.du.edu>
- Sender: usenet@mnemosyne.cs.du.edu (netnews admin account)
- Organization: Nyx, Public Access Unix @ U. of Denver Math/CS dept.
- Distribution: na
- Date: Tue, 15 Dec 92 07:10:41 GMT
- Lines: 47
-
-
- I have been trying to output floating point numbers to a DOS
- VGA screen graphics screen. I am using Borland 3.1 C++and
- EGAVGA.BGI. I found the below function in one of the example
- files. It works great but there is a problem. I want to only
- output 3 places right of the decimal point. I have tried
- setprecision(2) right in front of my floating point variable
- on the gprintf line. But it will not work. I know why and
- that is because it is no longer a floating point but a string.
- Does anyone have an idea of how to out smart this little
- function and only let it output 3 places right of the decimal
- point.
- .........Thanks!!...........
-
- GPRINTF: Used like PRINTF except the output is sent to the*/
- screen in graphics mode at the specified co-ordinate. */
-
-
- int gprintf( int *xloc, int *yloc, char *fmt, ... )
- {
- va_list argptr; /* Argument list pointer */
- char str[140]; /* Buffer to build sting into */
- int cnt; /* Result of SPRINTF for return /
-
- va_start( argptr, fmt ); /* Initialize va_ functions*/
-
- cnt = vsprintf( str, fmt, argptr ); /* prints string to buffer*/
- outtextxy( *xloc, *yloc, str); /* Send string in graphics mode */
- *yloc += textheight( "H" ) + 2; /* Advance to next line */
-
- va_end( argptr ); /* Close va_functions */
-
- return( cnt ); /* Return the conversion count*/
-
- / ************* BELOW is part of the include file *************
-
- typedef void _FAR *va_list;
-
- #define __size(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int)-1))
-
- #if defined(__cplusplus) && !defined(__STDC__)
- #define va_start(ap, parmN) (ap = ...)
- #else
- #define va_start(ap, parmN) ((void)((ap) = (va_list)((char _FAR
- *)(&parmN)+__size(parmN))))
- #endif
-
-