-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strmapi.c
61 lines (56 loc) · 2.01 KB
/
ft_strmapi.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kyungkim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 03:59:47 by kyungkim #+# #+# */
/* Updated: 2024/11/27 05:38:53 by kyungkim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int l;
int i;
l = ft_strlen(s);
str = (char *)malloc(l + 1);
if (!str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
i++;
}
str[i] = 0;
return (str);
}
/*
char alpha_mirror(unsigned int i, char c)
{
char new;
new = c;
(void)i;
if (('a' <= c && c <= 'm') || ('A' <= c && c <= 'M'))
new += 13;
else if (('n' <= c && c <= 'z') || ('N' <= c && c <= 'Z'))
new -= 13;
return (new);
}
int main(void)
{
printf("%s", ft_strmapi("Rnpu cebwrpg va gur 42 Pbzzba Pber pbagnvaf na rapbqrq"
" uvag. Sbe rnpu "
"pvepyr, bayl bar cebwrpg cebivqrf gur pbeerpg uvag arrqrq sbe gur"
"arkg pvepyr. Guvf punyyratr vf vaqvivqhny, jvgu n svany cevmr sbe"
"bar fghqrag. Fgnss zrzoref znl cnegvpvcngr ohg ner abg ryvtvoyr sbe n"
"cevmr. Ner lbh nzbat gur irel svefg gb fbyir n pvepyr? Fraq gur uvagf"
"jvgu rkcynangvbaf gb [email protected] gb or nqqrq gb gur yrnqreobneq. Gur"
"uvag sbe guvf svefg cebwrpg, juvpu znl pbagnva nantenzzrq jbeqf, vf:"
"Jbys bs ntragvir cnegvpyrf gung qvfcebir terral gb lbhe ubzrf qan"
"gung cebjfr lbhe fgbby", alpha_mirror));
}
*/