ft_striteri: initial implementation
This commit is contained in:
parent
f2f363518c
commit
6a186f7527
3 changed files with 62 additions and 2 deletions
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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue