Advertisement
levartolona

C_PRG_LANG_EX_4.1

Feb 1st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <limits.h>
  5.  
  6. #define ABS(n) n >= 0 ? n : -n
  7.  
  8. int strrindex(char *s, char *t)
  9. {
  10.     int r_index = -1;
  11.     char *start = s;
  12.     while(*s)
  13.     {
  14.         if (*s == *t)
  15.         {
  16.             int pos = 0;
  17.             for(; *(s + pos) != '\0' && *(t + pos) != '\0'
  18.                 && *(s + pos) == *(t + pos);)
  19.                 pos++;
  20.  
  21.             if (*(t + pos) == '\0')
  22.                 r_index = s - start;
  23.         }
  24.         s++;
  25.     }
  26.     return r_index;
  27. }
  28.  
  29.  
  30. int main(void)
  31. {
  32.     char *str = "qwe qwe rasrawdabc asdawd abcqwe";
  33.     char *search = "qwe";
  34.     printf("%i", strrindex(str, search));
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement