ft_strcapitalize.c

This commit is contained in:
Timo Schmidt 2023-03-19 11:44:47 +01:00
parent 7d4fe515b9
commit c41701f2d9
1 changed files with 53 additions and 0 deletions

53
ex09/ft_strcapitalize.c Normal file
View File

@ -0,0 +1,53 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcapitalize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/19 11:27:43 by tischmid #+# #+# */
/* Updated: 2023/03/19 11:44:36 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);
}
*/ ////