~ubuntu-branches/ubuntu/lucid/9base/lucid

« back to all changes in this revision

Viewing changes to lib9/fmt/test3.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

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