home *** CD-ROM | disk | FTP | other *** search
- /* ==( bench/ftoa.c )== */
-
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Nig 1-Jan-87 */
- /* Modified Nig 31-Jan-90 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 31-Jan-90 Nig - Check for Zero Length
- * 11-Dec-89 Geo - V2 version
- * 25-Oct-89 Geo - 1.32 Merge
- */
-
- /*
- * Function to Strip Off the Trailing Zeros from a string, created using a
- * sprintf(str, "%lf", num). Result is returned in STR
- *
- * Arguments : STR - String Containing Result
- * NUM - Number to be Converted
- * LEN - Max Length of String to be Returned
- */
-
- # include <stdio.h>
- # include <bench.h>
-
- # define FLTSIZE 81
-
- void f_to_a(str, num, len)
- char *str;
- double num;
- int len;
- {
- char *ptr;
- char lstr[FLTSIZE]; /* local string - sprintf needs a largish one */
-
- if (len == 0)
- *lstr = '\0';
- else
- sprintf(lstr, "%lf", num);
-
- if (strlen(lstr))
- {
- ptr = strchr(lstr, '\0');
- /* Strip Off the Trailing Zeros */
- do
- {
- ptr--;
- } while ((ptr > lstr) && (*ptr == '0'));
- *++ptr = '\0';
- ptr--;
-
- /* Make Sure New String is Not Too Long for its Destination Buffer */
- if (strlen(lstr) > len)
- {
- lstr[len] = '\0'; /* truncate */
- ptr = &lstr[len-1]; /* or lstr + len - 1 */
- }
-
- /*
- * Having Stripped Off Zeros & Extra Characters, if the Last
- * Character is a FULLSTOP, then Blat it.
- */
- if (*ptr == '.')
- *ptr = '\0';
- }
- strcpy(str, lstr);
- }
-
- void l_to_a(str, num, len)
- char *str;
- long num;
- int len;
- {
- char lstr[FLTSIZE]; /* local string - sprintf needs a largish one */
-
- sprintf(lstr, "%ld", num);
- lstr[len] = '\0'; /* truncate to max len */
- strcpy(str, lstr);
- }
-
-
- void i_to_a(str, num, len)
- char *str;
- int num;
- int len;
- {
- l_to_a(str, (long)num, len);
- }
-
-