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

73 lines
1.7 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:52:54 by cchauvet #+# #+# */
/* Updated: 2022/07/20 13:08:31 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);
}
/*
#include <stdio.h>
int main()
{
char str[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un";
printf("%s\n", str);
printf("%s", ft_strcapitalize(str));
}
*/