Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
664 B

  1. #include <stdio.h>
  2. #include "dict.h"
  3. #include "memory.h"
  4. int main() {
  5. int zero = 0;
  6. float one = 1.0;
  7. char two[] = "two";
  8. dictionary *d = dictionary_new();
  9. dictionary_add(d, "an int", &zero);
  10. dictionary_add(d, "a float", &one);
  11. for (size_t i = 0; i < 10; i++) {
  12. dictionary_add(d, "a string", &two);
  13. }
  14. printf("The integer I recorded was: %i\n", *(int*) dictionary_find(d, "an int"));
  15. printf("The string I recorded was: %s\n", (char*) dictionary_find(d, "a string"));
  16. dictionary *new_d = dictionary_copy(d);
  17. dictionary_free(d);
  18. unsigned int three = 3;
  19. dictionary_add(new_d, "an uint", &three);
  20. dictionary_free(new_d);
  21. }