8
8
9
9
typedef struct {
10
10
const char * name ;
11
- double age ;
11
+ long long age ;
12
12
const char * location ;
13
- double body_count ;
13
+ double cash ;
14
14
} Person ;
15
15
16
16
typedef struct {
@@ -26,11 +26,11 @@ bool parse_person(Jimp *jimp, Person *p)
26
26
if (strcmp (jimp -> member , "name" ) == 0 ) {
27
27
if (!jimp_string (jimp , & p -> name )) return false;
28
28
} else if (strcmp (jimp -> member , "age" ) == 0 ) {
29
- if (!jimp_number (jimp , & p -> age )) return false;
29
+ if (!jimp_int (jimp , & p -> age )) return false;
30
30
} else if (strcmp (jimp -> member , "location" ) == 0 ) {
31
31
if (!jimp_string (jimp , & p -> location )) return false;
32
- } else if (strcmp (jimp -> member , "body_count " ) == 0 ) {
33
- if (!jimp_number (jimp , & p -> body_count )) return false;
32
+ } else if (strcmp (jimp -> member , "cash " ) == 0 ) {
33
+ if (!jimp_float (jimp , & p -> cash )) return false;
34
34
} else {
35
35
jimp_unknown_member (jimp );
36
36
return false;
@@ -54,14 +54,14 @@ bool parse_people(Jimp *jimp, People *ps)
54
54
55
55
void print_person (const Person * p )
56
56
{
57
- printf ("name = %s\n" , p -> name );
58
- printf ("age = %lf \n" , p -> age );
59
- printf ("location = %s\n" , p -> location );
60
- printf ("body_count = %lf \n" , p -> body_count );
57
+ printf ("name = %s\n" , p -> name );
58
+ printf ("age = %lld \n" , p -> age );
59
+ printf ("location = %s\n" , p -> location );
60
+ printf ("cash = $%.2lf \n" , p -> cash );
61
61
}
62
62
63
63
typedef struct {
64
- long * items ;
64
+ JimpNumber * items ;
65
65
size_t count ;
66
66
size_t capacity ;
67
67
} Numbers ;
@@ -92,7 +92,7 @@ int main()
92
92
} else if (strcmp (jimp .member , "number" ) == 0 ) {
93
93
if (!jimp_array_begin (& jimp )) return 1 ;
94
94
while (jimp_array_item (& jimp )) {
95
- double x = 0 ;
95
+ JimpNumber x = { 0 } ;
96
96
if (!jimp_number (& jimp , & x )) return 1 ;
97
97
da_append (& xs , x );
98
98
}
@@ -109,8 +109,11 @@ int main()
109
109
printf ("\n" );
110
110
}
111
111
printf ("------------------------------\n" );
112
- da_foreach (long , x , & xs ) {
113
- printf ("%ld " , * x );
112
+ da_foreach (JimpNumber , x , & xs ) {
113
+ if (x -> type == JIMP_INTEGER )
114
+ printf ("%lld " , x -> value .i );
115
+ else
116
+ printf ("%lf " , x -> value .f );
114
117
}
115
118
printf ("\n" );
116
119
0 commit comments