42/d05/ex10/ft_strcapitalize.c

47 lines
1.3 KiB
C
Raw Permalink Normal View History

2016-11-20 02:20:23 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */
/* Updated: 2016/11/02 16:19:05 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
void to_lowercase(char *str)
{
while (*str)
{
if (*str >= 'A' && *str <= 'B')
{
*str += 32;
}
str++;
}
}
char *ft_strcapitalize(char *str)
{
char *begin;
begin = str;
to_lowercase(str);
while (*str)
{
if (*str >= 'a' && *str <= 'z')
{
if (*(str - 1) >= 'z')
*str -= 32;
if (*(str - 1) <= 'A')
*str -= 32;
if (*(str - 1) >= '0' && *(str - 1) <= '9')
*str += 32;
}
str++;
}
*str = '\0';
return (begin);
}