{"id":7666,"date":"2026-07-08T00:01:29","date_gmt":"2026-07-08T07:01:29","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7666"},"modified":"2026-07-04T13:29:37","modified_gmt":"2026-07-04T20:29:37","slug":"its-all-greek-solution","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7666","title":{"rendered":"It&#8217;s All Greek! &#8211; Solution"},"content":{"rendered":"<p>As a wrap-up for my ctype questions, <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7653\">this month&#8217;s Exercise<\/a> is to write a ctype function that converts lowercase Greek letters to uppercase and vice-versa. This challenge isn&#8217;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.<br \/>\n<!--more--><br \/>\nThe code range for uppercase Greek letters is from 0x0391 through 0x03A9.<\/p>\n<p>The code range for lowercase Greek letters is from 0x03B1 through 0x3C9.<\/p>\n<p>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 <em>toGupper()<\/em> and <em>toGlower()<\/em> functions:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2026_07-Exercise.c\" rel=\"noopener\" target=\"_blank\">2026_07-Exercise.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;wchar.h&gt;\r\n#include &lt;locale.h&gt;\r\n\r\n<span class=\"comments\">\/* convert Greek lowercase to uppercase *\/<\/span>\r\nwchar_t toGupper(wchar_t c)\r\n{\r\n    if( c&gt;=0x03B1 &amp;&amp; c&lt;=0x03C9 )\r\n        return( c-0x20 );\r\n    return(c);\r\n}\r\n\r\n<span class=\"comments\">\/* convert Greek uppercase to lowercase *\/<\/span>\r\nwchar_t toGlower(wchar_t c)\r\n{\r\n    if( c&gt;=0x0391 &amp;&amp; c&lt;=0x03A9 )\r\n        return( c+0x20 );\r\n    return(c);\r\n}\r\n\r\nint main()\r\n{\r\n    int x;\r\n    wchar_t phrase[] = L\"\u039e\u03b5\u03c3\u03ba\u03b5\u03c0\u03b1\u03b6\u03c9 \u03c4\u03b7\u03bd \u03a8\u03c5\u03c7\u03bf\u03c6\u03b8\u03bf\u03c1\u03b1 \u0392\u03b4\u03b5\u03bb\u03c5\u03b3\u03bc\u03b9\u03b1\";\r\n\r\n    <span class=\"comments\">\/* set the locale *\/<\/span>\r\n    setlocale(LC_ALL,\"\");\r\n\r\n    <span class=\"comments\">\/* output original phrase *\/<\/span>\r\n    wprintf(L\"Original:\\n\");\r\n    x = 0;\r\n    while(phrase[x])\r\n    {\r\n        putwchar(phrase[x]);\r\n        x++;\r\n    }\r\n    putwchar(L'\\n');\r\n\r\n    <span class=\"comments\">\/* output all caps (GREEK) *\/<\/span>\r\n    wprintf(L\"ALL CAPS:\\n\");\r\n    x = 0;\r\n    while(phrase[x])\r\n    {\r\n        putwchar(toGupper(phrase[x]));\r\n        x++;\r\n    }\r\n    putwchar(L'\\n');\r\n\r\n    <span class=\"comments\">\/* output lowercase (GREEK) *\/<\/span>\r\n    wprintf(L\"lowercase:\\n\");\r\n    x = 0;\r\n    while(phrase[x])\r\n    {\r\n        putwchar(toGlower(phrase[x]));\r\n        x++;\r\n    }\r\n    putwchar(L'\\n');\r\n\r\n    return 0;\r\n}<\/pre>\n<p>Both the <em>toGupper()<\/em> and <em>toGlower()<\/em> functions start with a range test. The Unicode values for the Greek letter uppercase and lowercase are compared with argument <code>c<\/code>. For <em>toGupper()<\/em>, if variable <code>c<\/code> is in the lowercase Greek character range, the value 0x20 is subtracted and the result &mdash; the corresponding uppercase Greek letter &mdash; is returned. The opposite approach is used in the <em>toGlower(<\/em>) function, where 0x20 is added to the letter&#8217;s Unicode value.<\/p>\n<p>The <em>main(<\/em>) function processes the characters in <em>wchar_t<\/em> array <code>phrase[]<\/code> 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:<\/p>\n<pre>Original:\r\n\u039e\u03b5\u03c3\u03ba\u03b5\u03c0\u03b1\u03b6\u03c9 \u03c4\u03b7\u03bd \u03a8\u03c5\u03c7\u03bf\u03c6\u03b8\u03bf\u03c1\u03b1 \u0392\u03b4\u03b5\u03bb\u03c5\u03b3\u03bc\u03b9\u03b1\r\nALL CAPS:\r\n\u039e\u0395\u03a3\u039a\u0395\u03a0\u0391\u0396\u03a9 \u03a4\u0397\u039d \u03a8\u03a5\u03a7\u039f\u03a6\u0398\u039f\u03a1\u0391 \u0392\u0394\u0395\u039b\u03a5\u0393\u039c\u0399\u0391\r\nlowercase:\r\n\u03be\u03b5\u03c3\u03ba\u03b5\u03c0\u03b1\u03b6\u03c9 \u03c4\u03b7\u03bd \u03c8\u03c5\u03c7\u03bf\u03c6\u03b8\u03bf\u03c1\u03b1 \u03b2\u03b4\u03b5\u03bb\u03c5\u03b3\u03bc\u03b9\u03b1<\/pre>\n<p>Writing comprehensive versions of <em>toGupper()<\/em> and <em>toGlower()<\/em> functions requires adding the accents and breathing marks. The accents appear above the vowels \u03b1, \u03b5, \u03b7, \u03b9, \u03bf, \u03c5, and \u03c9. They are acute (\u03ac), grave (\u1f70), and circumflex (\u1fb6). The breathing marks can also appear above vowels but also for the character \u03c1 (rho) at the start of a word. Two breathing marks are used: rough (\u1fe5) and smooth (\u1fe4).<\/p>\n<p>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.<\/p>\n<p>Congratulations if your solution met with success!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a wrap-up for my ctype questions, this month&#8217;s Exercise is to write a ctype function that converts lowercase Greek letters to uppercase and vice-versa. This challenge isn&#8217;t a steep hill to climb, once you know the pattern of Unicode &hellip; <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7666\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-7666","post","type-post","status-publish","format-standard","hentry","category-solution"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7666"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7666\/revisions"}],"predecessor-version":[{"id":7680,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7666\/revisions\/7680"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}