ft_striteri: initial implementation
This commit is contained in:
parent
f2f363518c
commit
6a186f7527
3 changed files with 62 additions and 2 deletions
5
Makefile
5
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: kcolin <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
|
||||
|
|
|
|||
58
ft_striteri.c
Normal file
58
ft_striteri.c
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
1
libft.h
1
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue