-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_dreplace.c
35 lines (32 loc) · 1.2 KB
/
ft_dreplace.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
35
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_dreplace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/20 16:58:02 by ohachim #+# #+# */
/* Updated: 2018/10/20 17:00:13 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_dreplace(const char *s, char tor, char r)
{
char *dups;
size_t len;
size_t cn;
cn = 0;
len = ft_strlen(s);
if (!(dups = (char*)malloc(len + 1)))
return (NULL);
while (s[cn] != '\0')
{
if (s[cn] == tor)
dups[cn] = r;
else
dups[cn] = s[cn];
cn++;
}
dups[cn] = '\0';
return (dups);
}