piscine-c02/ex09/ft_strcapitalize.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/19 11:48:17 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcapitalize(char *str)
{
int i;
int inside_word;
int is_alpha;
int is_numeric;
char c;
inside_word = 0;
i = -1;
while (str[++i] != '\0')
{
c = str[i];
is_alpha = ((c | 32) >= 'a' && (c | 32) <= 'z');
is_numeric = (c >= '0' && c <= '9');
if (!inside_word && (is_alpha || is_numeric))
{
inside_word = 1;
if (is_alpha)
str[i] = str[i] & 95;
}
else if (inside_word && (is_alpha || is_numeric))
str[i] = str[i] | 32;
else
inside_word = 0;
}
return (str);
}
/* ////
#include <stdio.h>
int main(void)
{
char s1[] = "hallo mein name ist timo und das ist ein 13371G3R TEXT hier";
char *s2;
s2 = ft_strcapitalize(s1);
printf("%s\n", s2);
return (0);
}
*/ ////