1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
42-2nd-piscine/finish/C02/ex09/ft_strcapitalize.c
2023-08-03 23:16:27 +02:00

37 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 18:12:38 by adjoly #+# #+# */
/* Updated: 2023/07/18 21:24:58 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcapitalize(char *str)
{
int i;
i = 0;
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 32;
i++;
while (str[i])
{
if ((str[i] >= 'a' && str[i] <= 'z')
&& !((str[i - 1] >= '0' && str[i - 1] <= '9')
|| (str[i - 1] >= 'a' && str[i - 1] <= 'z')
|| (str[i - 1] >= 'A' && str[i - 1] <= 'Z')))
str[i] -= 32;
else if (str[i] >= 'A' && str[i] <= 'Z'
&& ((str[i - 1] >= '0' && str[i - 1] <= '9')
|| (str[i - 1] >= 'a' && str[i - 1] <= 'z')
|| (str[i - 1] >= 'A' && str[i - 1] <= 'Z')))
str[i] += 32;
i++;
}
return (str);
}