mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-12-30 04:33:01 +00:00
- scanf test. Verifies the operation of scanning floats
This commit is contained in:
parent
6bae989841
commit
c3959c4d16
41
lib/libc/tests/stdio/scanftst.c
Executable file
41
lib/libc/tests/stdio/scanftst.c
Executable file
@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user