home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / recio213.zip / rputf.c < prev    next >
C/C++ Source or Header  |  1995-09-05  |  2KB  |  70 lines

  1. /*****************************************************************************
  2.    MODULE: rputf.c
  3.   PURPOSE: recio character delimited floating point output functions
  4. COPYRIGHT: (C) 1994-1995, William Pierpoint
  5.  COMPILER: Borland C Version 3.1
  6.        OS: MSDOS Version 6.2
  7.   VERSION: 2.13
  8.   RELEASE: September 4, 1995
  9. *****************************************************************************/
  10.  
  11. #include <float.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. #include "recio.h"
  17.  
  18. extern char *dtoa(double d, char *str, int dig);
  19. extern int _risready(REC *rp, int mode);
  20. extern int _rputc(REC *rp, int ch);
  21.  
  22. #define rfp(rp)          ((rp)->r_fp)
  23. #define rcol(rp)         ((rp)->r_colno)
  24. #define rfldch(rp)       ((rp)->r_fldch)
  25. #define rflags(rp)       ((rp)->r_flags)
  26.  
  27. /****************************************************************************/
  28. static void                  /* returns nothing                             */
  29.     _rputd(                  /* output floating point number to rec stream  */
  30.         REC *rp,             /* pointer to record stream                    */
  31.         int dig,             /* number of significant digits                */
  32.         double num)          /* floating point number                       */
  33. /****************************************************************************/
  34.     if (_risready(rp, R_WRITE)) { 
  35.         rfldno(rp)++; 
  36.         rflags(rp) &= ~_R_TXT;
  37.  
  38.         /* if not first field, put field separator if not null */
  39.         if (rfldno(rp) > 1 && rfldch(rp)) { 
  40.             if (_rputc(rp, rfldch(rp))) goto done; 
  41.         } 
  42.  
  43.         /* convert number to string */
  44.         dtoa(num, _r_nsbuf, dig); 
  45.  
  46.         /* output converted string */
  47.         if (fputs(_r_nsbuf, rfp(rp)) != EOF) { 
  48.             rcol(rp) += strlen(_r_nsbuf); 
  49.         } else { 
  50.             rseterr(rp, R_ENOPUT); 
  51.         } 
  52.     } 
  53. done:
  54.     return; 
  55. }
  56.  
  57. /****************************************************************************/
  58. /* character delimited floating point output functions                      */
  59. /****************************************************************************/
  60. void rputf(REC *rp, float num)
  61. {
  62.     _rputd(rp, FLT_DIG, (double) num);
  63. }
  64.  
  65. void rputd(REC *rp, double num)
  66. {
  67.     _rputd(rp, DBL_DIG, num);
  68. }
  69.