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.

41 lines
1.0KB

  1. #include "uthash.h"
  2. #include <stdio.h>
  3. #include <stdlib.h> /* malloc */
  4. typedef struct person_t {
  5. char first_name[10];
  6. int id;
  7. UT_hash_handle hh;
  8. } person_t;
  9. int main()
  10. {
  11. person_t *people=NULL, *person;
  12. const char **name;
  13. const char * names[] = { "bob", "jack", "gary", "ty", "bo", "phil", "art",
  14. "gil", "buck", "ted", NULL
  15. };
  16. int id=0;
  17. for(name=names; *name != NULL; name++) {
  18. person = (person_t*)malloc(sizeof(person_t));
  19. if (person == NULL) {
  20. exit(-1);
  21. }
  22. strcpy(person->first_name, *name);
  23. person->id = id++;
  24. HASH_ADD_STR(people,first_name,person);
  25. printf("added %s (id %d)\n", person->first_name, person->id);
  26. }
  27. for(name=names; *name != NULL; name++) {
  28. HASH_FIND_STR(people,*name,person);
  29. if (person != NULL) {
  30. printf("found %s (id %d)\n", person->first_name, person->id);
  31. } else {
  32. printf("failed to find %s\n", *name);
  33. }
  34. }
  35. return 0;
  36. }