strings.c 886 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <assert.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <strings.h>
  5. int main() {
  6. assert(!bcmp("hello", "hehe", 2));
  7. assert(bcmp("hello", "haha", 2));
  8. char* new = malloc(3);
  9. bcopy("hi", new, 3); // include nul byte
  10. assert(!strcasecmp("hi", new));
  11. assert(strcasecmp("he", new));
  12. assert(!strcasecmp("hello", "HEllO"));
  13. assert(strcasecmp("hello", "HEllOo"));
  14. assert(!strncasecmp("hello", "Hello World", 5));
  15. assert(!strncasecmp("FLOOR0_1", "FLOOR0_1FLOOR4_1", 8));
  16. assert(strncasecmp("FL00RO_1", "FLOOR0_1FLOOR4_1", 8));
  17. bzero(new, 1);
  18. assert(*new == 0);
  19. assert(*(new+1) == 'i');
  20. assert(*(new+2) == 0);
  21. assert(ffs(1) == 1);
  22. assert(ffs(2) == 2);
  23. assert(ffs(3) == 1);
  24. assert(ffs(10) == 2);
  25. char* str = "hihih";
  26. assert(index(str, 'i') == str + 1);
  27. assert(rindex(str, 'i') == str + 3);
  28. }