Advertisement
Guest User

Implement strrev function

a guest
Oct 18th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. #include <stdio.h>
  2. char    *my_strrev(char *str)
  3. {
  4.     int     i;
  5.     int     j;
  6.     char    swap;
  7.  
  8.     i = 0;
  9.     j = 0;
  10.     while (str[i] != '\0')
  11.         i++;
  12.     i--;
  13.     while (i > j)
  14.     {
  15.         swap = str[i];
  16.         str[i] = str[j];
  17.         str[j] = swap;
  18.         i--;
  19.         j++;
  20.     }
  21.     return (str);
  22. }
  23.  
  24. int main()
  25. {
  26.     printf("%s\n", my_strrev("hello Sbu!!!"));
  27.     system("pause");
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement