-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strrev.c
33 lines (30 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrev.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dskrypny <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/30 20:24:29 by dskrypny #+# #+# */
/* Updated: 2017/12/09 12:38:38 by dskrypny ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrev(char *s)
{
char *str;
size_t len;
size_t i;
if (!s)
return (NULL);
i = 0;
len = ft_strlen(s);
if (!(str = (char *)malloc(sizeof(char) * (len + 1))))
return (NULL);
while (s[i])
{
str[i++] = s[len-- - 1];
}
str[i] = '\0';
return (s);
}