私はCプログラミングの初心者で、システム日付を使用してCコードを介して昨日の日付を取得しようとしており、このyesterdayDate_dtmmddyyのように文字列「yesterdayDate_dt」に追加しますが、実行時エラー「バスエラー10」に直面しています。
以下の私のコード
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
int main(void)
{
time_t now = time(NULL);
struct tm *t = localtime(&now);
int dInt = t->tm_mday+1;
int mInt = t->tm_mon -1;
int yInt = t->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;
}