64 lines
1.7 KiB
C
64 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strcapitalize.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/06/06 15:57:01 by whaffman #+# #+# */
|
|
/* Updated: 2024/06/09 17:29:10 by whaffman ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int ft_is_num(char c)
|
|
{
|
|
return (c >= '0' && c <= '9');
|
|
}
|
|
|
|
int ft_is_upper(char c)
|
|
{
|
|
return (c >= 'A' && c <= 'Z');
|
|
}
|
|
|
|
int ft_is_lower(char c)
|
|
{
|
|
return (c >= 'a' && c <= 'z');
|
|
}
|
|
|
|
int ft_is_alphanumeric(char c)
|
|
{
|
|
return (ft_is_num(c) || ft_is_upper(c) || ft_is_lower(c));
|
|
}
|
|
|
|
char *ft_strcapitalize(char *str)
|
|
{
|
|
int first_letter;
|
|
char *org_str;
|
|
|
|
org_str = str;
|
|
first_letter = 1;
|
|
while (*str)
|
|
{
|
|
if (first_letter && ft_is_lower(*str))
|
|
*str = *str - 'a' + 'A';
|
|
if (!first_letter && ft_is_upper(*str))
|
|
*str = *str - 'A' + 'a';
|
|
if (ft_is_alphanumeric(*str))
|
|
first_letter = 0;
|
|
else
|
|
first_letter = 1;
|
|
str++;
|
|
}
|
|
return (org_str);
|
|
}
|
|
/*
|
|
#include <stdio.h>
|
|
int main(void)
|
|
{
|
|
char str[] = "salut, comment tu vas ? 42mots quaRante-deux; cinquante+et+un";
|
|
ft_strcapitalize(&str[0]);
|
|
printf("%s", str);
|
|
return (0);
|
|
}
|
|
*/
|