ciabatta/test/test.c

38 lines
950 B
C
Raw Normal View History

2022-06-02 13:08:59 +00:00
#include <assert.h>
#include <ctype.h>
2022-06-06 00:16:44 +00:00
#include <stdio.h>
2022-06-05 22:02:54 +00:00
#include <stdlib.h>
2022-06-06 00:26:32 +00:00
#include <errno.h>
int main(int argc, char** argv) {
2022-06-06 00:16:44 +00:00
for (int i = 0; i < argc; i++) {
printf("[%d] = %s\n", i, argv[i]);
}
printf("%d\n", 583875381);
printf("%.*s", (int)3, "Hello");
for (char c = 'a'; c != 'z'; ++c) {
assert(isupper(toupper(c)));
2022-06-02 13:08:59 +00:00
}
2022-06-06 00:26:32 +00:00
2022-06-05 22:02:54 +00:00
double v0 = strtod("0X1.BC70A3D70A3D7P+6", NULL);
// parsing with error handling
const char *p = "111.11 -2.22 Nan nan(2) inF 0X1.BC70A3D70A3D7P+6 1.18973e+4932zzz";
2022-06-06 00:26:32 +00:00
2022-06-05 22:02:54 +00:00
char *end;
2022-06-06 00:26:32 +00:00
for (double f = strtod(p, &end); p != end; f = strtod(p, &end)) {
printf("'%.*s' -> ", (int)(end - p), p);
p = end;
2022-06-05 22:02:54 +00:00
if (errno == ERANGE){
2022-06-06 00:26:32 +00:00
printf("range error, got ");
2022-06-05 22:02:54 +00:00
}
2022-06-06 00:26:32 +00:00
printf("%f\n", f);
2022-06-02 13:08:59 +00:00
}
2022-06-06 00:26:32 +00:00
// parsing without error handling
2022-06-05 22:02:54 +00:00
double v1 = strtod(" -0.0000000123junk", NULL);
double v2 = strtod("junk", NULL);
}