// Test. cpp: defines the entry point for the console application.
//
# Include "stdafx. H"
# Include <stdio. h>
# Include <string. h>
Void formatdbltostr (double d_in, char * str_int, char * str_decmal );
Int main (INT argc, char * argv [])
{
Char str_int [8 + 1];
Char str_decmal [4 + 1];
Memset (str_int, 0x00, sizeof (str_int ));
Memset (str_decmal, 0x00, sizeof (str_decmal ));
Double D = 12.34;
Formatdbltostr (D, str_int, str_decmal );
Printf ("str_int = % s/n", str_int );
Printf ("str_decmal = % s/n", str_decmal );
Return 0;
}
Void formatdbltostr (double d_in, char * str_int, char * str_decmal)
{
/* Definition of local variables */
Char A [20];
Char B [20];
Char C [20];
Char E [20];
/* Initialize local variables */
Memset (A, 0x00, sizeof ());
Memset (B, 0x00, sizeof (B ));
Memset (C, 0x00, sizeof (c ));
Memset (E, 0x00, sizeof (e ));
/* Print the integer to */
Sprintf (a, "%. 0lf", d_in );
/* Print all to B */
Sprintf (B, "%. 4lf", d_in );
/* Copy the fractional part of B to C */
Memcpy (C, B + strlen (A) + 1, strlen (B)-strlen (a)-1 );
/* Print an integer of 8 digits */
Sprintf (E, "% 8.0lf", d_in );
/* Output result */
Memcpy (str_int, E, strlen (e ));
Memcpy (str_decmal, C, strlen (c ));
}