| 60 if (janes_phone == NULL) printf("Jane's number was deleted.\n"); |
60 if (janes_phone == NULL) printf("Jane's number was deleted.\n"); |
| 61 |
61 |
| 62 // Iterate through the contact list |
62 // Iterate through the contact list |
| 63 CxMapIterator iter = cxMapIterator(contacts); |
63 CxMapIterator iter = cxMapIterator(contacts); |
| 64 cx_foreach(CxMapEntry *, entry, iter) { |
64 cx_foreach(CxMapEntry *, entry, iter) { |
| 65 cxstring name = cx_strn(entry->key->data, entry->key->len); |
65 cxstring name = cx_hash_key_as_string(entry->key); |
| 66 const char *phone = entry->value; |
66 const char *phone = entry->value; |
| 67 printf("%" CX_PRIstr ": %s\n", CX_SFMT(name), phone); |
67 printf("%" CX_PRIstr ": %s\n", CX_SFMT(name), phone); |
| 68 } |
68 } |
| 69 |
69 |
| 70 cxMapFree(contacts); |
70 cxMapFree(contacts); |
| 158 } |
158 } |
| 159 } else if (input[0] == '4') { |
159 } else if (input[0] == '4') { |
| 160 // Almost the same iteration loop as above ... |
160 // Almost the same iteration loop as above ... |
| 161 CxMapIterator iter = cxMapIterator(contacts); |
161 CxMapIterator iter = cxMapIterator(contacts); |
| 162 cx_foreach(CxMapEntry *, entry, iter) { |
162 cx_foreach(CxMapEntry *, entry, iter) { |
| 163 cxstring name = cx_strn(entry->key->data, |
163 cxstring name = cx_hash_key_as_string(entry->key); |
| 164 entry->key->len); |
|
| 165 // ... except that here we get cxmutstr* |
164 // ... except that here we get cxmutstr* |
| 166 cxmutstr *phone = entry->value; |
165 cxmutstr *phone = entry->value; |
| 167 printf("%" CX_PRIstr ": %" CX_PRIstr "\n", |
166 printf("%" CX_PRIstr ": %" CX_PRIstr "\n", |
| 168 CX_SFMT(name), CX_SFMT(*phone)); |
167 CX_SFMT(name), CX_SFMT(*phone)); |
| 169 } |
168 } |