From c3959c4d16599d0b9d83565b6db3c3f23c4b9cb3 Mon Sep 17 00:00:00 2001 From: gdr-ftp Date: Wed, 4 Feb 1998 07:24:39 +0000 Subject: [PATCH] - scanf test. Verifies the operation of scanning floats --- lib/libc/tests/stdio/scanftst.c | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 lib/libc/tests/stdio/scanftst.c diff --git a/lib/libc/tests/stdio/scanftst.c b/lib/libc/tests/stdio/scanftst.c new file mode 100755 index 0000000..c061945 --- /dev/null +++ b/lib/libc/tests/stdio/scanftst.c @@ -0,0 +1,41 @@ +#include +#include + +int +main (int argc, char **argv) { + register int i, j; + double d; + char *p; + + while(1) { + printf("enter an integer:\n"); + i = scanf("%d", &j); + if (i<0) exit (1); + if (i > 0) { + printf("scanf returned %d. j == %d\n", i, j); + } else { + printf("invalid input: enter an integer\n"); + continue; + } + d = 5.5; + printf("enter a float. 5.5 = %g\t", d); + p = (char *) &d; + for (j = 0; j < sizeof(double); j++) { + printf("%x ", *p++); + } + printf("\n"); + i = scanf("%lf", &d); + if (i<0) exit (1); + if (i > 0) { + printf("i = %d, d = %g\n", i, d); + p = (char *) &d; + for (j = 0; j < sizeof(double); j++) { + printf("%x ", *p++); + } + printf("\n"); + } else { + printf("invalid input: enter a double\n"); + } + } + return 0; +}