54 lines
1.6 KiB
C
54 lines
1.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strcapitalize.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/03/19 11:27:43 by tischmid #+# #+# */
|
|
/* Updated: 2023/03/24 01:37:33 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
char *ft_strcapitalize(char *str)
|
|
{
|
|
int inside_word;
|
|
int is_alpha;
|
|
int is_numeric;
|
|
char *orig_str;
|
|
|
|
orig_str = str;
|
|
inside_word = 0;
|
|
while (*str)
|
|
{
|
|
is_alpha = ((*str | 32) >= 'a' && (*str | 32) <= 'z');
|
|
is_numeric = (*str >= '0' && *str <= '9');
|
|
if (!inside_word && (is_alpha || is_numeric))
|
|
{
|
|
inside_word = 1;
|
|
if (is_alpha)
|
|
*str &= 95;
|
|
}
|
|
else if (inside_word && is_alpha)
|
|
*str |= 32;
|
|
else
|
|
inside_word = 0;
|
|
++str;
|
|
}
|
|
return (orig_str);
|
|
}
|
|
|
|
/* ////
|
|
#include <stdio.h>
|
|
#define STR "salut, com0123456789ment tu vas ? 42" \
|
|
"mots quarante-deux; cinquante+et+un"
|
|
|
|
int main(void)
|
|
{
|
|
printf(STR "\n");
|
|
char s1[] = STR;
|
|
printf("%s\n", ft_strcapitalize(s1));
|
|
return (0);
|
|
}
|
|
*/ ////
|