62 lines
1.5 KiB
C
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/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);
|
||
|
}
|