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.

54 lines
1.1KB

  1. #include <stdio.h>
  2. #include "utarray.h"
  3. static int strsort(const void *_a, const void *_b)
  4. {
  5. const char *a = *(const char* const *)_a;
  6. const char *b = *(const char* const *)_b;
  7. return strcmp(a,b);
  8. }
  9. int main()
  10. {
  11. UT_array *strs;
  12. const char *s, **p;
  13. utarray_new(strs,&ut_str_icd);
  14. s = "hello";
  15. utarray_push_back(strs, &s);
  16. s = "world";
  17. utarray_push_back(strs, &s);
  18. s = "one";
  19. utarray_push_back(strs, &s);
  20. s = "two";
  21. utarray_push_back(strs, &s);
  22. s = "three";
  23. utarray_push_back(strs, &s);
  24. p = NULL;
  25. while ( (p=(const char**)utarray_next(strs,p)) != NULL ) {
  26. s = *p;
  27. printf("%s\n",s);
  28. }
  29. printf("sorting\n");
  30. utarray_sort(strs,strsort);
  31. p = NULL;
  32. while ( (p=(const char**)utarray_next(strs,p)) != NULL ) {
  33. s = *p;
  34. printf("finding %s\n",s);
  35. #ifdef __cplusplus
  36. p = (const char**)utarray_find(strs,&s,strsort);
  37. #else
  38. p = utarray_find(strs,&s,strsort);
  39. #endif
  40. printf(" %s\n", (p != NULL) ? (*p) : "failed");
  41. }
  42. utarray_free(strs);
  43. return 0;
  44. }