Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int len(const char str[]) {
  4. int i = 0;
  5. while(*str++) i++;
  6.  
  7. return i;
  8. }
  9.  
  10. int find_char(const char str[], char c) {
  11. if(len(str) == 0) return -1;
  12. int i = 0;
  13. while(*str) {
  14. if(*str++ == c)
  15. return i;
  16. i++;
  17. }
  18. return -1;
  19. }
  20.  
  21. int rfind_char(const char str[], char c) {
  22. if(len(str) == 0) return -1;
  23. int i = 0;
  24. int last = 0;
  25. while(*str) {
  26. if(*str++ == c)
  27. last = i;
  28. i++;
  29. }
  30. return last;
  31. }
  32.  
  33.  
  34.  
  35. int main() {
  36.  
  37.  
  38. printf("%d\n%d", find_char("To jest test", 's') , rfind_char("To jest test", 's'));
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement