Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include "stdio.h"
  2.  
  3. int     ft_strlen(char *string)
  4. {
  5.     int i;
  6.  
  7.     i = 0;
  8.     if (!string || !*string)
  9.         return (0);
  10.     while (string[i])
  11.         ++i;
  12.     return (i);
  13. }
  14.  
  15. char    *ft_strrev(char *string)
  16. {
  17.     int     Acounter;
  18.     int     Bcounter;
  19.     char    temp[ft_strlen(string) + 1];
  20.  
  21.     Acounter = 0;
  22.     Bcounter = 0;
  23.  
  24.     if (!string || !*string)
  25.         return (string);
  26.     while (string[Acounter])
  27.         Acounter++;
  28.     while (Acounter > 0)
  29.     {
  30.         Acounter--;
  31.         temp[Bcounter++] = string[Acounter];
  32.     }
  33.     while (Bcounter-- > 0)
  34.     {
  35.         (string[Acounter] = temp[Acounter]);
  36.         Acounter++;
  37.     }
  38.     return (string);
  39. }
  40.  
  41. int     main(void)
  42. {
  43.     char string[27] = "Death to the false emperor";
  44.  
  45.     printf ("result = %s", ft_strrev(string));
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement