-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
53 lines (49 loc) · 1.57 KB
/
ft_strmapi.c
File metadata and controls
53 lines (49 loc) · 1.57 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_strmapi.c :+: :+: */
/* +:+ */
/* By: pzlatov <pzlatov@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2024/10/23 12:13:52 by pzlatov #+# #+# */
/* Updated: 2024/10/25 22:15:55 by pzlatov ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *dst;
i = 0;
dst = (char *)malloc((ft_strlen(s) + 1) * sizeof(char));
if (!dst)
return (NULL);
while (i < ft_strlen(s))
{
dst[i] = (f)(i, s[i]);
i++;
}
dst[i] = '\0';
return (dst);
}
// static char to_upp(unsigned int index, char ch)
// {
// if (ch >= 'a' && ch <= 'z' && index != 1337)
// {
// ch -= 32;
// }
// return (ch);
// }
// int main()
// {
// char str[] = "hello world!";
// char *result = ft_strmapi(str, to_upper);
// if (result)
// {
// printf("new string: %s\n", result);
// free(result);
// }
// else
// printf("Oopsie");
// return 0;
// }