potat-dev/cpplabs

Lowercase is not working

Closed this issue · 2 comments

Function that converts a character to lowercase does not work correctly

https://github.com/DenCoder618/SUAI-Labs/blob/b4f24c5ce8cedea0318080affee271b9a0aba78d/Semester_1/Lab_5/Lab_5_dop.c#L56

Example input:
HelloComMa WorldDoT How r UqStn

Expected output:
Hello, World. How r U?

But the program does not perform the replacement

I rewrote the algorithm for converting a letter to lowercase (StackOverflow)

char tolower(int c)
{
    // (int)a = 97, (int)A = 65
    // (a)97 - (A)65 = 32
    // therefore 32 + 65 = a
    return c > 64 && c < 91 ? c + 32 : c;
}

It can be written shorter:

#define tolower(c) c > 64 && c < 91 ? c + 32 : c
#define tolower(c) c > 64 && c < 91 ? c + 32 : c

not working...