-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strmapi.c
More file actions
46 lines (42 loc) · 1.39 KB
/
Copy pathft_strmapi.c
File metadata and controls
46 lines (42 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/18 21:06:35 by kjurkows #+# #+# */
/* Updated: 2026/06/25 17:41:13 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//# Part 2
//## string creation
//import `malloc`
#include <stdlib.h>
/** @brief map a string
*
* @param s string to map
* @param f function used for mapping
* @return new string
* @retval 0 mapping failed
*/
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
const size_t len = ft_strlen(s);
size_t i;
char *str;
if (!s || !f)
return (0);
str = malloc(len + 1);
if (!str)
return (0);
i = 0;
while (i < len)
{
str[i] = f(i, s[i]);
i++;
}
str[i] = 0;
return (str);
}