title: Enum and a function that returns the month name as a string
body: <p>This is the exercise:</p>
  <blockquote>
  <p>Write  a   function    called <code>monthName()</code>    that    takes   as  its argument    a   value   of  type <code>enum month</code> (as   defined in  this    chapter)    and returns a   pointer to  a   character   string containing   the name    of  the month.  In  this    way,    you can display the value   of  an  <code>enum month</code> variable   with    a   statement   such    as:</p>
  <p><code>printf(&quot;%s\n&quot;, monthName(aMonth));</code></p>
  </blockquote>
  <p>I wrote my version and got the output I expected. However, I am sure that there must be a much better way to implement this without having to use a switch statement with one case for each month. How can I write this function with better design?</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  enum month { January = 1, February, March, April, May, June, 
          July, August, September, October, November, December };
  
  char *monthName(enum month m){
      switch (m) {
          case January:
              return &quot;January&quot;;
              break;
          case February:
              return &quot;February&quot;;
              break;
          case March:
              return &quot;March&quot;;
              break;
          case April:
              return &quot;April&quot;;
              break;
          case May:
              return &quot;May&quot;;
              break;
          case June:
              return &quot;June&quot;;
              break;
          case July:
              return &quot;July&quot;;
              break;
          case August:
              return &quot;August&quot;;
              break;
          case September:
              return &quot;September&quot;;
              break;
          case October:
              return &quot;October&quot;;
              break;
          case November:
              return &quot;November&quot;;
              break;
          case December:
              return &quot;December&quot;;
              break;
          default:
              return &quot;Not a valid month&quot;;
      }
  }
  
  int main(void)
  {
      enum month aMonth = 1;
  
      printf(&quot;%s\n&quot;, monthName(aMonth));
  
      aMonth = 2;
      printf(&quot;%s\n&quot;, monthName(aMonth));
  
      aMonth = 6;
      printf(&quot;%s\n&quot;, monthName(aMonth));
  
      return 0;
  }
  </code></pre>