Advertisement
Guest User

Untitled

a guest
May 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. char *my_strrchr (char *str, int ch)
  2. {
  3. char *res = NULL;
  4. while (*str)
  5. if (ch == *str++)
  6. res = str - 1;
  7. if (*str == ch)
  8. res = str;
  9. return res;
  10. }
  11.  
  12. char *my_strchr (char *str, int ch)
  13. {
  14. while (*str)
  15. if (ch == *str++)
  16. return --str;
  17. if (*str == ch)
  18. return str;
  19. return NULL;
  20. }
  21.  
  22. size_t my_strcspn(char *str1, char *str2)
  23. {
  24. int i = 0;
  25. while (*str1)
  26. {
  27. char *ptr = str2;
  28. int res = 0;
  29. while (*ptr)
  30. res += (*str1 == *ptr++);
  31. if (res)
  32. return i;
  33. i++;
  34. str1++;
  35. }
  36. return i;
  37. }
  38.  
  39. size_t my_strspn(char *str1, char *str2)
  40. {
  41. int i = 0;
  42. while (*str1)
  43. {
  44. char *ptr = str2;
  45. int res = 0;
  46. while (*ptr)
  47. res += (*str1 == *ptr++);
  48. if (!res)
  49. return i;
  50. i++;
  51. str1++;
  52. }
  53. return i;
  54. }
  55.  
  56. char *my_strbrk(char *str1, char *str2)
  57. {
  58. while (*str1)
  59. {
  60. char *ptr = str2;
  61. while (*ptr)
  62. if(*str1 == *ptr++)
  63. return str1;
  64. str1++;
  65. }
  66. return NULL;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement