libft/ft_striteri.c
2024-10-18 12:11:55 +02:00

58 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/18 12:04:53 by kcolin #+# #+# */
/* Updated: 2024/10/18 12:10:29 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
unsigned int i;
i = 0;
while (s[i] != '\0')
{
(*f)(i, s + i);
i++;
}
}
/*
#include "libft.h"
#include <stdio.h>
void upcase_some_letters(unsigned int i, char *c)
{
if (i % 2 == 0)
*c = ft_toupper(*c);
else
*c = ft_tolower(*c);
}
int main(int argc, char **argv)
{
if (argc > 1)
{
int i = 1;
while (i < argc)
{
ft_striteri(argv[i], &upcase_some_letters);
printf("%d\t'%s'\n", i, argv[i]);
i++;
}
return (0);
}
else
{
printf("Usage: %s <text...>\n", argv[0]);
return (1);
}
}
*/