{"id":5901,"date":"2023-06-03T00:01:49","date_gmt":"2023-06-03T07:01:49","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=5901"},"modified":"2023-06-10T10:10:11","modified_gmt":"2023-06-10T17:10:11","slug":"pairs-of-arrays","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=5901","title":{"rendered":"Pairs of Arrays"},"content":{"rendered":"<p>I enjoy studying foreign languages. A tool like Google Translate comes in handy, but it&#8217;s not perfect. That&#8217;s because computers translate words and phrases, but not the living, spoken language. Regardless, I thought I&#8217;d give language translation a stab, which got me into the topic of exploring arrays.<br \/>\n<!--more--><br \/>\nThe easiest parts of speech to translate are nouns. These pair up fairly well between most languages. For example, numbers translate directly between all languages. But for my program, I sought to translate months of the year. The languages chosen are French and English, one of which I speak fairly well.<\/p>\n<p>Before my brain entangled itself in the process of how to input a word from one language and output its foreign tongue complement, I first wanted to output the names of months as they pair up.<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2023_06_03-Lesson.c\" rel=\"noopener\" target=\"_blank\">2023_06_03-Lesson.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;string.h&gt;\r\n\r\n#define MONTHS 12\r\n\r\nint main()\r\n{\r\n    const char *english[MONTHS] =\r\n    {\r\n        \"January\", \"February\", \"March\", \"April\",\r\n        \"May\", \"June\", \"July\", \"August\", \"September\",\r\n        \"October\", \"November\", \"December\"\r\n    };\r\n    const char *french[MONTHS] =\r\n    {\r\n        \"janvier\", \"fevrier\", \"mars\", \"avril\",\r\n        \"mai\", \"juin\", \"jullet\", \"aout\", \"septembre\",\r\n        \"octobre\", \"novembre\", \"decembre\"\r\n    };\r\n    int x;\r\n\r\n    <span class=\"comments\">\/* output months *\/<\/span>\r\n    for( x=0; x&lt;MONTHS; x++ )\r\n        printf(\"%s - %s\\n\", english[x], french[x]);\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The code hosts two arrays, <code>english[]<\/code> and <code>french[]<\/code>. Both are pointer arrays, each with <code>MONTH<\/code> (12) elements in their annual order. These are constant arrays as their values don&#8217;t change, nor should they be changed due to the string-pointer declaration. (<a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4938\">Relevant post<\/a>.)<\/p>\n<p>The <em>for<\/em> loop processes the arrays and outputs the corresponding values:<\/p>\n<p><code>January - janvier<br \/>\nFebruary - fevrier<br \/>\nMarch - mars<br \/>\nApril - avril<br \/>\nMay - mai<br \/>\nJune - juin<br \/>\nJuly - jullet<br \/>\nAugust - aout<br \/>\nSeptember - septembre<br \/>\nOctober - octobre<br \/>\nNovember - novembre<br \/>\nDecember - decembre<\/code><\/p>\n<p>Upon success, I sought to devise a translation function that would output the French month name when given the English month name. That&#8217;s where I stopped.<\/p>\n<p>My primitive attempts at translation work only when a link exists between the two arrays. In this Lesson&#8217;s code the link exists because each element in each array pairs up with the translated word. In the program I started to write, input is accepted and the offset passed to a function that returns the corresponding word. While this program worked, I found it to be unimpressive. It was a lot of code to do what something else could accomplish a lot easier.<\/p>\n<p>That something else, something that the C language is missing, is called an <em>associative array<\/em>. I explore this concept in <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5903\">next week&#8217;s Lesson<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For each item in one array, a companion item is found in the second. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=5901\">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":[2],"tags":[],"class_list":["post-5901","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5901","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=5901"}],"version-history":[{"count":3,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5901\/revisions"}],"predecessor-version":[{"id":5915,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/5901\/revisions\/5915"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5901"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5901"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5901"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}