Research portable Memory game | Исследовать портируемую игру Память
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.

38 lines
874B

  1. #include "uthash.h"
  2. #include <string.h> /* strcpy */
  3. #include <stdlib.h> /* malloc */
  4. #include <stdio.h> /* printf */
  5. typedef struct elt {
  6. char *s;
  7. UT_hash_handle hh;
  8. } elt;
  9. int main()
  10. {
  11. int i;
  12. elt *head = NULL;
  13. elt elts[10];
  14. char label[6] = "hello";
  15. for(i=0; i<10; i++) {
  16. elts[i].s = (char*)malloc(6UL);
  17. strcpy(elts[i].s, "hello");
  18. elts[i].s[0] = 'a' + i;
  19. printf("%d: %s\n", i, elts[i].s);
  20. HASH_ADD_KEYPTR(hh, head, elts[i].s, 6UL, &elts[i]);
  21. }
  22. /* look up each element and verify the result pointer */
  23. for(i=0; i<10; i++) {
  24. elt *e;
  25. label[0] = 'a' + i;
  26. HASH_FIND(hh,head,label,6UL,e);
  27. if (e != NULL) {
  28. printf( "found %s\n", e->s);
  29. printf( "right address? %s\n", (e == &elts[i]) ? "yes" : "no");
  30. }
  31. }
  32. return 0;
  33. }