42_C_PISCINE/C/c02v3/ex09/ft_strcapitalize.c
Camille Chauvet 29ed24d567 init
2023-05-17 16:45:25 +00:00

62 lines
1.5 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:52:54 by cchauvet #+# #+# */
/* Updated: 2022/07/22 09:20:34 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_lower(char c)
{
if ('a' <= c && c <= 'z')
return (1);
return (0);
}
int ft_is_upper(char c)
{
if ('A' <= c && c <= 'Z')
return (1);
return (0);
}
int ft_is_alpha(char c)
{
if (ft_is_lower(c) || ft_is_upper(c))
return (1);
return (0);
}
int ft_is_digit(char c)
{
if ('0' <= c && c <= '9')
return (1);
return (0);
}
char *ft_strcapitalize(char *str)
{
int i;
i = 1;
if (ft_is_lower(str[0]))
str[0] -= 32;
while (str[i] != 0)
{
if (!(ft_is_alpha(str[i - 1]) || ft_is_digit(str[i - 1])))
{
if (ft_is_lower(str[i]))
str[i] -= 32;
}
else
if (ft_is_upper(str[i]))
str[i] += 32;
i++;
}
return (str);
}