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.

49 lines
1002B

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "utarray.h"
  4. typedef struct {
  5. int a;
  6. char *s;
  7. } intchar_t;
  8. static void intchar_copy(void *_dst, const void *_src)
  9. {
  10. intchar_t *dst = (intchar_t*)_dst;
  11. const intchar_t *src = (const intchar_t*)_src;
  12. dst->a = src->a;
  13. dst->s = (src->s != NULL) ? strdup(src->s) : NULL;
  14. }
  15. static void intchar_dtor(void *_elt)
  16. {
  17. intchar_t *elt = (intchar_t*)_elt;
  18. if (elt->s != NULL) {
  19. free(elt->s);
  20. }
  21. }
  22. int main()
  23. {
  24. UT_array *intchars;
  25. intchar_t ic, *p;
  26. UT_icd intchar_icd = {sizeof(intchar_t), NULL, intchar_copy, intchar_dtor};
  27. utarray_new(intchars, &intchar_icd);
  28. ic.a=1;
  29. ic.s=(char*)"hello";
  30. utarray_push_back(intchars, &ic);
  31. ic.a=2;
  32. ic.s=(char*)"world";
  33. utarray_push_back(intchars, &ic);
  34. p=NULL;
  35. while( (p=(intchar_t*)utarray_next(intchars,p)) != NULL ) {
  36. printf("%d %s\n", p->a, (p->s != NULL) ? p->s : "null");
  37. }
  38. utarray_free(intchars);
  39. return 0;
  40. }