libft
src
ft_strcapitalize.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* ft_strcapitalize.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2019/09/06 22:51:50 by unite #+# #+# */
10
/* Updated: 2020/07/16 02:52:28 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
libft.h
"
15
16
static
int
scroll_to_word(
char
**s)
17
{
18
while
(**s)
19
{
20
if
(
ft_isalnum
(**s))
21
return
(1);
22
*s += 1;
23
}
24
return
(0);
25
}
26
27
static
void
capitalize_word(
char
**s)
28
{
29
**s =
ft_toupper
(**s);
30
*s += 1;
31
while
(
ft_isalnum
(**s))
32
{
33
**s =
ft_tolower
(**s);
34
*s += 1;
35
}
36
}
37
51
char
*
ft_strcapitalize
(
const
char
*s1)
52
{
53
char
*s2;
54
55
if
(!s1 || !(s2 =
ft_strdup
(s1)))
56
return
(0);
57
while
(scroll_to_word(&s2))
58
capitalize_word(&s2);
59
return
(s2);
60
}
ft_strdup
char * ft_strdup(const char *s1)
Replicates behaviour of strdup from libc.
Definition:
ft_strdup.c:20
ft_isalnum
int ft_isalnum(int c)
Replicates behaviour of isalnum from libc.
Definition:
ft_isalnum.c:20
ft_toupper
int ft_toupper(int c)
Replicates behaviour of toupper from libc.
Definition:
ft_toupper.c:20
ft_strcapitalize
char * ft_strcapitalize(const char *s1)
Capitalizes all words in a string.
Definition:
ft_strcapitalize.c:51
libft.h
ft_tolower
int ft_tolower(int c)
Replicates behaviour of tolower from libc.
Definition:
ft_tolower.c:20
Generated by
1.8.16