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.

39 lines
843B

  1. #include "uthash.h"
  2. #include <time.h>
  3. #include <stdlib.h> /* malloc */
  4. #include <stdio.h> /* printf */
  5. typedef struct example_user_t {
  6. int id;
  7. int cookie;
  8. UT_hash_handle hh;
  9. } example_user_t;
  10. int main()
  11. {
  12. int i;
  13. example_user_t *user, *tmp, *users=NULL;
  14. /* create elements */
  15. for(i=0; i<10; i++) {
  16. user = (example_user_t*)malloc(sizeof(example_user_t));
  17. if (user == NULL) {
  18. exit(-1);
  19. }
  20. user->id = i;
  21. user->cookie = i*i;
  22. HASH_ADD_INT(users,id,user);
  23. }
  24. /* find each even ID */
  25. for(i=0; i<10; i+=2) {
  26. HASH_FIND_INT(users,&i,tmp);
  27. if (tmp != NULL) {
  28. printf("user id %d found, cookie %d\n", tmp->id, tmp->cookie);
  29. } else {
  30. printf("user id %d not found\n", i);
  31. }
  32. }
  33. return 0;
  34. }