title: C - Concat Strings
body: <p>Trying to concat strings (*char) using C and having a lot of segmentation faults:</p>
  
  <pre><code>void printDateFormat( char *in ) { /* begin function printDateFormat */
  
     char *month;          // month by char
     int month_int;        // month by digit
     char *day;            // day by char
     char *year;           // year by char
     char *dateToken;      // date token in split
     char *formatted;      // formatted string
  
     dateToken = strtok (in, "/");
     month = &amp;dateToken;
  
     formatted = formatted = getMonth(month);
  
     dateToken = strtok (NULL, "/");
     day = &amp;dateToken;
  
     formatted = strcat (formatted, day);
     formatted = strcat (formatted, ", ");
  
     dateToken = strtok (NULL, "/");
     year = &amp;dateToken;
  
     formatted = strcat (formatted, year);
  
     in = *formatted;
  
  } /* End function printDateFormat */
  
  
  char *getMonth( int d) { /* begin function *getMonth */
  
  switch (d) {
  
    case 1:
       return "January";
   //    break;
    case 2:
       return "February";
   //    break;
    case 3:
       return "March";
   //    break;
    case 4:
       return "April";
  //     break;
    case 5:
       return "May";
  //     break;
    case 6:
       return "June";
  //     break;
    case 7:
       return "July";
  //     break;
    case 8:
       return "August";
  //     break;
    case 9:
       return "September";
  //     break;
    case 10:
       return "October";
   //    break;
    case 11:
       return "November";
  //     break;
    case 12:
       return "December";
  //     break;
     }
  
  } /* End function *getMonth */
  </code></pre>
  
  <p>Input into printDateFormat() is expected as another string in the format: MM/dd/yyyy ... ie. 03/31/2013. Purpose is to turn that into: March 31, 2013.</p>
  
  <p>EDIT:</p>
  
  <p>Here's how I pass into <code>printDateFormat</code></p>
  
  <pre><code>void option1( void ) { /* begin function option1 */
  
      char date[10]; /*user input date string */
  
      printf("\n\nEnter date [Format: MM/dd/yyyy]: ");
      fgets(date, 10, stdin);
  
      scanf("%s", &amp;date);
  
      printDateFormat(date);
  
      printf("\n%s", date);
  
  } /* End function option2 */
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>Ok, made a few changes but still no dice... </p>
  
  <p>here's my compiler warning:</p>
  
  <pre><code>asgn9.c: In function `printDateFormat':
  asgn9.c:224: warning: passing arg 1 of `getMonth' makes integer from pointer without a cast
  asgn9.c:237: warning: assignment makes pointer from integer without a cast
  </code></pre>
  
  <p>they refer to the use of <code>getMonth()</code> within my <code>printDateFormat()</code></p>
  
  <p>Here's my updated code, I still get a segmentation fault at the same spot... </p>
  
  <pre><code>void printDateFormat( char *in ) { /* begin function printDateFormat */
  
      char *month;          // month by char
      int month_int;        // month by digit
      char *day;            // day by char
      char *year;           // year by char
      char *dateTkn;      // date token in split
      char *formatted;      // formatted string
  
      dateTkn = strtok (in, "/");
      month = dateTkn;
  
      formatted = getMonth(month);
  
      dateTkn = strtok (NULL, "/");
      day = dateTkn;
  
      formatted = strcat (formatted, day);
      formatted = strcat (formatted, ", ");
  
      dateTkn = strtok (NULL, "/");
      year = dateTkn;
  
      formatted = strcat (formatted, year);
  
      in = *formatted;
  
  } /* End function printDateFormat */
  
  char *getMonth( int d) { /* begin function *getMonth */
  
      static char *months[] = {"January", "February", "March", "April", "May",
          "June", "July", "August", "September", "October", "November", "December"};
  
      return strcpy(malloc(32), months[d]);
  
  } /* End function *getMonth */
  </code></pre>