42_C_PISCINE/C/c02v2/ex09/ft_strcapitalize.c

62 lines
1.5 KiB
C
Raw Normal View History

2023-05-17 12:45:25 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:52:54 by cchauvet #+# #+# */
/* Updated: 2022/07/24 11:30:49 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[i] -= 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);
}