diff --git a/Makefile b/Makefile index ad46b57..fd1a337 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: kcolin +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/10/14 13:43:59 by kcolin #+# #+# # -# Updated: 2024/10/18 11:33:48 by kcolin ### ########.fr # +# Updated: 2024/10/18 12:11:14 by kcolin ### ########.fr # # # # **************************************************************************** # @@ -40,7 +40,8 @@ SOURCES = ft_isalpha.c \ ft_strtrim.c \ ft_split.c \ ft_itoa.c \ - ft_strmapi.c + ft_strmapi.c \ + ft_striteri.c OBJECTS = $(SOURCES:.c=.o) CC = gcc diff --git a/ft_striteri.c b/ft_striteri.c new file mode 100644 index 0000000..f5ddb9c --- /dev/null +++ b/ft_striteri.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: kcolin +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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 + +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 \n", argv[0]); + return (1); + } +} +*/ diff --git a/libft.h b/libft.h index 0421dd6..0e096b5 100644 --- a/libft.h +++ b/libft.h @@ -55,5 +55,6 @@ char **ft_split(char const *s, char c); char *ft_itoa(int n); char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); #endif