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.1KB

  1. #include <stdio.h> /* printf */
  2. #include "utstring.h"
  3. int main()
  4. {
  5. UT_string *s,*t;
  6. char V_TestStr[] = "There are two needle\0s in this \0haystack with needle\0s.";
  7. char V_NeedleStr[] = "needle\0s";
  8. long V_FindPos;
  9. size_t V_FindCnt;
  10. utstring_new(s);
  11. utstring_new(t);
  12. utstring_bincpy(s, V_TestStr, sizeof(V_TestStr)-1);
  13. printf("\"%s\" len=%u\n", utstring_body(s), (unsigned)utstring_len(s));
  14. utstring_bincpy(t, V_NeedleStr, sizeof(V_NeedleStr)-1);
  15. printf("\"%s\" len=%u\n", utstring_body(t), (unsigned)utstring_len(t));
  16. V_FindCnt = 0;
  17. V_FindPos = 0;
  18. do {
  19. V_FindPos = utstring_find(s,
  20. V_FindPos,
  21. utstring_body(t),
  22. utstring_len(t));
  23. printf("utstring_find()=%ld\n", V_FindPos);
  24. if (V_FindPos >= 0) {
  25. V_FindPos++;
  26. V_FindCnt++;
  27. }
  28. } while (V_FindPos >= 0);
  29. printf("FindCnt=%u\n", (unsigned)V_FindCnt);
  30. utstring_free(s);
  31. utstring_free(t);
  32. return 0;
  33. }