roberts@crash.cts.com (Robert Schwalbe) (09/26/89)
Have there been any reports of problems with any of the C library
routines? I'm having one heck of a time trying to get sscanf to
work with float's. The following could get compiled as a MPW (3.0)
tool for displaying my problems. The make file is also included.
#include <StdIO.h>
#include <Types.h>
main ()
{
/*============*/
/* PROBLEM #1 */
/*============*/
{
Str255 string1 = "1.234\0";
float float1 = 0.0;
int retval = 0;
/* Why does float1 not receive the value of 1.234 ? */
printf("Expected results : %s\n", string1);
retval = sscanf(string1, "%5.3f", &float1);
printf("Actual results : %5.3f retval=%d\n\n", float1, retval);
}
/*===============*/
/* SOLUTION #1 ? */
/*===============*/
{
Str255 string2 = "4.321\0";
extended extended1 = 0.0;
int retval = 0;
/* But extended1 does receive the value of 4.321. Is sscanf */
/* restricted to *only* work with extended's? */
printf("Expected results : %s\n", string2);
retval = sscanf(string2, "%Lf", &extended1);
printf("Actual results : %5.3f retval=%d\n\n", extended1, retval
}
/*============*/
/* PROBLEM #2 */
/*============*/
/* Why does the following statement not get padded with zeroes? */
printf("Expected results : 0000002.76\n");
printf("Actual results : %010.2f\n", 2.76);
}
Link -w -c 'MPS ' -t MPST 6
{OBJECTS} 6
"{Libraries}"stubs.o 6
"{CLibraries}"CRuntime.o 6
"{Libraries}"Interface.o 6
"{CLibraries}"StdCLib.o 6
"{CLibraries}"CSANELib.o 6
"{CLibraries}"Math.o 6
"{CLibraries}"CInterface.o 6
"{Libraries}"ToolLibs.o 6
-o filename
NAME: Robert Schwalbe
UUCP: [ hplabs!hp-sdd | sdcsvax | nosc ]!crash!roberts
ARPA: crash!roberts@nosc
INET: roberts@crash.CTS.COM