88
99typedef struct {
1010 const char * name ;
11- double age ;
11+ long long age ;
1212 const char * location ;
13- double body_count ;
13+ double cash ;
1414} Person ;
1515
1616typedef struct {
@@ -26,11 +26,11 @@ bool parse_person(Jimp *jimp, Person *p)
2626 if (strcmp (jimp -> member , "name" ) == 0 ) {
2727 if (!jimp_string (jimp , & p -> name )) return false;
2828 } 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;
3030 } else if (strcmp (jimp -> member , "location" ) == 0 ) {
3131 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;
3434 } else {
3535 jimp_unknown_member (jimp );
3636 return false;
@@ -54,14 +54,14 @@ bool parse_people(Jimp *jimp, People *ps)
5454
5555void print_person (const Person * p )
5656{
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 );
6161}
6262
6363typedef struct {
64- long * items ;
64+ JimpNumber * items ;
6565 size_t count ;
6666 size_t capacity ;
6767} Numbers ;
@@ -92,7 +92,7 @@ int main()
9292 } else if (strcmp (jimp .member , "number" ) == 0 ) {
9393 if (!jimp_array_begin (& jimp )) return 1 ;
9494 while (jimp_array_item (& jimp )) {
95- double x = 0 ;
95+ JimpNumber x = { 0 } ;
9696 if (!jimp_number (& jimp , & x )) return 1 ;
9797 da_append (& xs , x );
9898 }
@@ -109,8 +109,11 @@ int main()
109109 printf ("\n" );
110110 }
111111 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 );
114117 }
115118 printf ("\n" );
116119
0 commit comments