-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strcapitalize.c
42 lines (38 loc) · 1.46 KB
/
ft_strcapitalize.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dalves-p <dalves-p@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/06 20:25:35 by dalves-p #+# #+# */
/* Updated: 2022/05/27 12:56:47 by dalves-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** LIBRARY: N/A
** DESCRIPTION:
** The ft_strcapitalize() function capitalizes the first letter of each word
** and transforms all other letters to lowercase.
*/
char *ft_strcapitalize(char *str)
{
int i;
i = 0;
ft_strlowcase(str);
while (str[i] != '\0')
{
if (str[0] >= 97 && str[0] <= 122)
str[0] = str[0] - 32;
if (str[i + 1] >= 97 && str[i + 1] <= 122)
{
if ((str[i] < 48) || (str[i] > 57 && str[i] < 65))
str[i + 1] = str[i + 1] - 32;
if ((str[i] > 90 && str[i] < 97) || (str[i] > 122))
str[i + 1] = str[i + 1] - 32;
}
i++;
}
return (str);
}