0
if (!(a[i] >= 65 && a[i] <= 90)
            && !(a[i] >= 97 && a[i] <= 122)
            && !(a[i] >= 48 && a[i] <= 57)
            && (a[i + 1] >= 97 && a[i + 1] <= 122))
void    kucult(char *a)
{
    int i;

    i = 0;
    while (a[i])
    {
        if (a[i] >= 65 && a[i] <= 90)
        {
            a[i] += 32;
        }
        i++;
    }
}

void    kontrol(char    *a)
{
    int i;

    i = 0;
    while (a[i])
    {
        if (!(a[i] >= 65 && a[i] <= 90)
            && !(a[i] >= 97 && a[i] <= 122)
            && !(a[i] >= 48 && a[i] <= 57)
            && (a[i + 1] >= 97 && a[i + 1] <= 122))
        {
            a[i + 1] -= 32;
        }
        i++;
    }
}

char    *ft_strcapitalize(char  *str)
{
    int i;

    i = 0;
    kucult(str);
    if (i == 0 && (str[i] <= 122 && str[i] >= 97))
    {
        str[i] -= 32;
    }
    kontrol(str);
    return (str);
}

 #include <stdio.h>
 
 int main(void)
{
    char a[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un";
    ft_strcapitalize(a);
    printf("%s", a );   

}
4mu2
  • 1
  • 1
  • 7
    All programmers ought to study [De Morgan's Laws](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) as a prerequisite before writing source code. – Lundin Oct 28 '22 at 06:43
  • 2
    [Logical Operators](https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Logical_operators) – Ocaso Protal Oct 28 '22 at 06:44
  • 2
    So basically `!` is logical NOT, `&&` is logical AND and you can apply De Morgan's Laws from there to make more sense of the code, if you don't already understand it as-is. – Lundin Oct 28 '22 at 06:46
  • 1
    Besides the operator you asked about, that is terrible code. Don't take this as a example how to write code. You should never use such a mess of magic numbers. If characters are meant, they should be used instead. I.e. first lines would be: `!(a[i] >= 'A' && a[i] <= 'Z') && !(a[i] >= 'a' && a[i] <= 'z')` or better `!isalpha(a[i])` – Gerhardh Oct 28 '22 at 08:23

0 Answers0