66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strmapi.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/18 11:34:37 by kcolin #+# #+# */
|
|
/* Updated: 2024/10/18 11:52:51 by kcolin ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
#include <stdlib.h>
|
|
|
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
{
|
|
unsigned int i;
|
|
char *out;
|
|
|
|
out = ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
|
if (out == NULL)
|
|
return (NULL);
|
|
i = 0;
|
|
while (s[i] != '\0')
|
|
{
|
|
out[i] = (*f)(i, s[i]);
|
|
i++;
|
|
}
|
|
return (out);
|
|
}
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
|
|
char upcase_some_letters(unsigned int i, char c)
|
|
{
|
|
if (i % 2 == 0)
|
|
return (ft_toupper(c));
|
|
else
|
|
return (ft_tolower(c));
|
|
}
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
if (argc > 1)
|
|
{
|
|
int i = 1;
|
|
|
|
while (i < argc)
|
|
{
|
|
char *out = ft_strmapi(argv[i], &upcase_some_letters);
|
|
printf("%d\t'%s'\n", i, out);
|
|
free(out);
|
|
i++;
|
|
}
|
|
return (0);
|
|
}
|
|
else
|
|
{
|
|
printf("Usage: %s <text...>\n", argv[0]);
|
|
return (1);
|
|
}
|
|
}
|
|
*/
|