test3.c (867B)
1 #include <libc.h> 2 #include <stdio.h> 3 #include <u.h> 4 5 void test(char* fmt, ...) { 6 va_list arg; 7 char fmtbuf[100], stdbuf[100]; 8 9 va_start(arg, fmt); 10 vsnprint(fmtbuf, sizeof fmtbuf, fmt, arg); 11 va_end(arg); 12 13 va_start(arg, fmt); 14 vsnprint(stdbuf, sizeof stdbuf, fmt, arg); 15 va_end(arg); 16 17 if (strcmp(fmtbuf, stdbuf) != 0) 18 print("fmt %s: fmt=\"%s\" std=\"%s\"\n", fmt, fmtbuf, stdbuf); 19 20 print("fmt %s: %s\n", fmt, fmtbuf); 21 } 22 23 24 int main(int argc, char* argv[]) { 25 test("%f", 3.14159); 26 test("%f", 3.14159e10); 27 test("%f", 3.14159e-10); 28 29 test("%e", 3.14159); 30 test("%e", 3.14159e10); 31 test("%e", 3.14159e-10); 32 33 test("%g", 3.14159); 34 test("%g", 3.14159e10); 35 test("%g", 3.14159e-10); 36 37 test("%g", 2e25); 38 test("%.18g", 2e25); 39 40 test("%2.18g", 1.0); 41 test("%2.18f", 1.0); 42 test("%f", 3.1415927 / 4); 43 44 test("%20.10d", 12345); 45 test("%0.10d", 12345); 46 47 return 0; 48 }