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.

35 lines
825B

  1. #include <string.h> /* memcpy */
  2. #include <stdlib.h> /* malloc */
  3. #include <stdio.h> /* printf */
  4. #include "uthash.h"
  5. struct my_struct {
  6. char bkey[5]; /* "binary" key */
  7. int data;
  8. UT_hash_handle hh;
  9. };
  10. int main()
  11. {
  12. struct my_struct *s, *t, *bins = NULL;
  13. char binary[5] = {'\3','\1','\4','\1','\6'};
  14. /* allocate our structure. initialize to some values */
  15. s = (struct my_struct*)calloc(1UL,sizeof(struct my_struct));
  16. if (s == NULL) {
  17. exit(-1);
  18. }
  19. memcpy(s->bkey, binary, sizeof(binary));
  20. /* add to hash table using general macro */
  21. HASH_ADD( hh, bins, bkey, sizeof(binary), s);
  22. /* look up the structure we just added */
  23. HASH_FIND( hh, bins, binary, sizeof(binary), t );
  24. if (t != NULL) {
  25. printf("found\n");
  26. }
  27. return 0;
  28. }