Simple API usage exampleΒΆ

The following example demonstrates almost zero-effort method of parsing format string.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "fmt_parser.h"
#include "fmt_util.h"
#include <stdio.h>

int main()
{
    fmt_status  rc;
    fmt_spec    spec;
    const char *str = "Hello, %157$02ld test %*s world!";
    const char *tmp = str;

    do
    {
        fmt_spec_init(&spec);
        rc = fmt_read_one(&tmp, &spec);
        if (rc == FMT_EOK)
        {
            fmt_spec_print(&spec, stdout);
            printf("\n");
        }
    } while (fmt_read_is_ok(rc));

    return 0;
}