init
This commit is contained in:
61
Correction/matyss/ex09/ft_strcapitalize.c
Normal file
61
Correction/matyss/ex09/ft_strcapitalize.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcapitalize.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/18 10:52:54 by cchauvet #+# #+# */
|
||||
/* Updated: 2022/07/21 14:19:13 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);
|
||||
}
|
Reference in New Issue
Block a user