-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strrev.c
34 lines (31 loc) · 1.15 KB
/
ft_strrev.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nromptea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/12/04 17:58:54 by nromptea #+# #+# */
/* Updated: 2015/12/09 19:00:01 by nromptea ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrev(char *s)
{
int i;
int len;
char *rev;
i = 0;
len = ft_strlen(s);
if (!(rev = (char *)malloc(sizeof(char) * len + 1)))
return (NULL);
if (s[len] == '\0')
len--;
while (len >= 0)
{
rev[i] = s[len];
i++;
len--;
}
return (rev);
}