title: How to get yesterday's date from system date and append to string?
body: <p>I am a beginner in C programming and trying to get the yesterday’s date through c code using system date and append in the string "yesterdayDate_dt" like this yesterdayDate_dtmmddyy but facing run time error “bus error 10” .</p>
  
  <p>My code as below
   </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;time.h&gt;
  #include &lt;string.h&gt;
   
  int main(void)
  {
     time_t now = time(NULL);
     struct tm *t = localtime(&amp;now);
   
    int dInt = t-&gt;tm_mday+1;
    int mInt = t-&gt;tm_mon -1;
    int yInt = t-&gt;tm_year+1900;
    char *date= "23";
    char *month = "01";
    char *year = "13";
   
    sprintf(date, "%d", dInt);
    sprintf(month, "%d", mInt);
   
     char *yestDt = (char *)malloc(strlen(date)+strlen(month)+strlen(year)+1);
     strcpy(str,month);
     strcat(str,date);
     strcat(str,year);
     printf("str:%s",yestDt);
     return 0;
  }
  </code></pre>