As a wrap-up for my ctype questions, this month’s Exercise is to write a ctype function that converts lowercase Greek letters to uppercase and vice-versa. This challenge isn’t a steep hill to climb, once you know the pattern of Unicode Greek letter values, and ignore the required accent and breathing marks that frequently adorn various letters.
The code range for uppercase Greek letters is from 0x0391 through 0x03A9.
The code range for lowercase Greek letters is from 0x03B1 through 0x3C9.
The difference between these two ranges is 0x20, which is the same difference between upper- and lowercase letters in ASCII for the Latin character set. To swap between character sets you add or subtract 0x20, which is what I did for my solution with the toGupper() and toGlower() functions:
2026_07-Exercise.c
#include <stdio.h> #include <wchar.h> #include <locale.h> /* convert Greek lowercase to uppercase */ wchar_t toGupper(wchar_t c) { if( c>=0x03B1 && c<=0x03C9 ) return( c-0x20 ); return(c); } /* convert Greek uppercase to lowercase */ wchar_t toGlower(wchar_t c) { if( c>=0x0391 && c<=0x03A9 ) return( c+0x20 ); return(c); } int main() { int x; wchar_t phrase[] = L"Ξεσκεπαζω την Ψυχοφθορα Βδελυγμια"; /* set the locale */ setlocale(LC_ALL,""); /* output original phrase */ wprintf(L"Original:\n"); x = 0; while(phrase[x]) { putwchar(phrase[x]); x++; } putwchar(L'\n'); /* output all caps (GREEK) */ wprintf(L"ALL CAPS:\n"); x = 0; while(phrase[x]) { putwchar(toGupper(phrase[x])); x++; } putwchar(L'\n'); /* output lowercase (GREEK) */ wprintf(L"lowercase:\n"); x = 0; while(phrase[x]) { putwchar(toGlower(phrase[x])); x++; } putwchar(L'\n'); return 0; }
Both the toGupper() and toGlower() functions start with a range test. The Unicode values for the Greek letter uppercase and lowercase are compared with argument c. For toGupper(), if variable c is in the lowercase Greek character range, the value 0x20 is subtracted and the result — the corresponding uppercase Greek letter — is returned. The opposite approach is used in the toGlower() function, where 0x20 is added to the letter’s Unicode value.
The main() function processes the characters in wchar_t array phrase[] three times. First, the original phrase is output. Then the phrase is output converted to uppercase, then finally lowercase. Here is output from a sample run of my solution:
Original: Ξεσκεπαζω την Ψυχοφθορα Βδελυγμια ALL CAPS: ΞΕΣΚΕΠΑΖΩ ΤΗΝ ΨΥΧΟΦΘΟΡΑ ΒΔΕΛΥΓΜΙΑ lowercase: ξεσκεπαζω την ψυχοφθορα βδελυγμια
Writing comprehensive versions of toGupper() and toGlower() functions requires adding the accents and breathing marks. The accents appear above the vowels α, ε, η, ι, ο, υ, and ω. They are acute (ά), grave (ὰ), and circumflex (ᾶ). The breathing marks can also appear above vowels but also for the character ρ (rho) at the start of a word. Two breathing marks are used: rough (ῥ) and smooth (ῤ).
The problem with a solution that includes accents and breathing marks is that only a few specific accented Greek letters are found in Unicode. The rough accents are specific characters, though without any pattern I can detect. Creating other accents and breathing marks accepts requires combining characters with multiple Unicode values. Such code is possible, but unduly complex.
Congratulations if your solution met with success!