summaryrefslogtreecommitdiff
path: root/ft_strmapi.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-03-10 13:35:18 +0100
committerDominik Kaiser2024-03-10 13:35:18 +0100
commit3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4 (patch)
tree4e2ac5e37895152cf1497ea7e5dc084bd510a1e6 /ft_strmapi.c
parentc63ee0defff25db4612e9114d847b5045948e366 (diff)
downloadlibft-3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4.tar.gz
libft-3c90d29fe5bf9ba6da090cd59c8c139d269f8bd4.zip
Add everything
Diffstat (limited to 'ft_strmapi.c')
-rw-r--r--ft_strmapi.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/ft_strmapi.c b/ft_strmapi.c
new file mode 100644
index 0000000..5d31408
--- /dev/null
+++ b/ft_strmapi.c
@@ -0,0 +1,46 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strmapi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2024/03/10 11:11:30 by dkaiser #+# #+# */
+/* Updated: 2024/03/10 13:19:18 by dkaiser ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
+{
+ char *result;
+ unsigned int i;
+
+ i = 0;
+ while (s[i])
+ i++;
+ result = malloc(sizeof(char) * (i + 1));
+ if (!result)
+ return (0);
+ result[i] = '\0';
+ i = 0;
+ while (s[i])
+ {
+ result[i] = f(i, s[i]);
+ i++;
+ }
+ return (result);
+}
+
+/* char func (unsigned int i, char c) */
+/* { */
+/* c += i; */
+/* return (c); */
+/* } */
+
+/* #include <stdio.h> */
+/* int main(){ */
+/* char str[] = "AAAAAAAA"; */
+/* printf("%s\n", ft_strmapi(str, func)); */
+/* } */