title: Building a date string in c
body: <p>I am currently working on a c project and I am trying to get the date from the system and build that into a string.</p>
  
  <p>I am very new to c so I'm currently learning as I go along but I cannot get this to work. Below is the code that I have</p>
  
  <pre><code>time_t now = time(NULL);
  struct tm *t = localtime(&amp;now);
  char currentDate[13];
  char day[3];
  char month[3];
  char year[5];
  char hour[3];
  char min[3];
  sprintf(day, "%02d", t-&gt;tm_mday, sizeof(day));
  sprintf(month, "%02d", t-&gt;tm_mon+1, sizeof(month));
  sprintf(year, "%04d", t-&gt;tm_year + 1900, sizeof(year));
  sprintf(hour, "%02d", t-&gt;tm_hour, sizeof(hour));
  sprintf(min, "%02d", t-&gt;tm_min, sizeof(min));
  strcat(currentDate, day);
  strcat(currentDate, month);
  strcat(currentDate, year);
  strcat(currentDate, hour);
  strcat(currentDate, min);
  printf("Current Date: %s", currentDate);
  </code></pre>
  
  <p>When it does the printf it just prints a load of rubbish e.g.</p>
  
  <blockquote>
    <p>Current Date: ÃÃxÂ·ZÂ¤Ã¿Â·Ã¸ÃÃÂ©Ã´ÃÃ¿Â·^XÃÃÂ©&lt;95>ÃºÃ¾Â·^F^FÃ^P^_</p>
  </blockquote>
  
  <p>What am I doing wrong. </p>